@@ -39,23 +39,41 @@ protected override void WndProc(ref Message message)
3939 switch ( ( WM ) message . Msg )
4040 {
4141 case WM . INPUT :
42+ {
43+ if ( message . LParam == IntPtr . Zero )
44+ {
45+ break ;
46+ }
47+ InputData rawBuffer ;
48+ var dwSize = 0 ;
49+ var res = User32 . GetRawInputData ( message . LParam , DataCommand . RID_INPUT , IntPtr . Zero , ref dwSize , Marshal . SizeOf ( typeof ( RawInputHeader ) ) ) ;
50+ if ( res != 0 )
51+ {
52+ var ex = new Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
53+ Logger . Error ( ex , "Error sizing the rawinput buffer: {0}" , ex . Message ) ;
54+ break ;
55+ }
56+
57+ res = User32 . GetRawInputData ( message . LParam , DataCommand . RID_INPUT , out rawBuffer , ref dwSize , Marshal . SizeOf ( typeof ( RawInputHeader ) ) ) ;
58+ if ( res == - 1 )
59+ {
60+ var ex = new Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
61+ Logger . Error ( ex , "Error getting the rawinput buffer: {0}" , ex . Message ) ;
62+ break ;
63+ }
64+ if ( res == dwSize )
4265 {
43- InputData _rawBuffer ;
44- var dwSize = 0 ;
45- User32 . GetRawInputData ( message . LParam , DataCommand . RID_INPUT , IntPtr . Zero , ref dwSize , Marshal . SizeOf ( typeof ( RawInputHeader ) ) ) ;
46- int res = User32 . GetRawInputData ( message . LParam , DataCommand . RID_INPUT , out _rawBuffer , ref dwSize , Marshal . SizeOf ( typeof ( RawInputHeader ) ) ) ;
47- if ( dwSize != res )
48- {
49- var ex = new Win32Exception ( Marshal . GetLastWin32Error ( ) ) ;
50- Logger . Error ( ex , "Error getting the rawinput buffer: {0}" , ex . Message ) ;
51- return ;
52- }
5366 foreach ( var device in _devices )
5467 {
55- device . ProcessRawInput ( _rawBuffer ) ;
68+ device . ProcessRawInput ( rawBuffer ) ;
5669 }
5770 }
58- break ;
71+ else
72+ {
73+ //Something is seriously f'd up with Windows - the number of bytes copied does not match the reported buffer size.
74+ }
75+ }
76+ break ;
5977 }
6078 base . WndProc ( ref message ) ;
6179 }
0 commit comments