Thanks for your help. Does this look right? The method does not return any
values other than zero in the structures. Here is the code:
/* typedef struct tagRAWINPUTHEAD ER {
DWORD dwType;
DWORD dwSize;
HANDLE hDevice;
WPARAM wParam;
} RAWINPUTHEADER, *PRAWINPUTHEADE R;*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWINPUTHEADER
{
private int Type;
private int Size;
private IntPtr Device;
private int wParam;
}
/*typedef struct tagRAWMOUSE
{
USHORT usFlags;
union
{
ULONG ulButtons;
struct
{
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformat ion;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct ButtonFlagsData
{
public UInt16 usButtonFlags;
public UInt16 usButtonData;
}
[ StructLayout( LayoutKind.Expl icit )]
public struct MyUnion
{
[FieldOffset(0)]
public UInt32 ulButtons;
[FieldOffset(0)]
ButtonFlagsData buttonFlagsData ;
}
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWMOUSE
{
public UInt16 Flags;
MyUnion myUnion;
public UInt32 RawButtons;
public Int32 LastX;
public Int32 LastY;
public UInt32 ExtraInformatio n;
}
[ StructLayout( LayoutKind.Expl icit )]
public struct BUTTONFLDAT
{
[ FieldOffset( 0 )]
public UInt16 ButtonFlags;
[ FieldOffset( 0 )]
public UInt16 ButtonData;
}
[ StructLayout( LayoutKind.Expl icit )]
public struct BUTTONS
{
[ FieldOffset( 0 )]
public UInt32 Buttons;
[ FieldOffset( 0 )]
public IntPtr buttonFlData;
}
/*typedef struct tagRAWHID {
DWORD dwSizeHid;
DWORD dwCount;
BYTE bRawData;
} RAWHID, **LPRAWHID*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWHID
{
public int SizeHid;
public int Count;
public System.Byte RawData;
}
/*typedef struct tagRAWKEYBOARD {
USHORT MakeCode;
USHORT Flags;
USHORT Reserved;
USHORT VKey;
UINT Message;
ULONG ExtraInformatio n;
} RAWKEYBOARD, *PRAWKEYBOARD, *LPRAWKEYBOARD;
*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWKEYBOARD
{
public System.Int16 MakeCode;
public System.Int16 Flags;
public System.Int16 Reserved;
public System.Int16 VKey;
public System.UInt32 Message;
public System.UInt32 ExtraInformanti on;
}
/*typedef struct tagRAWINPUT {
RAWINPUTHEADER header;
union {
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
} data;
} RAWINPUT, *PRAWINPUT; *LPRAWINPUT;*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct MyUnion2
{
RAWMOUSE mouse;
RAWKEYBOARD keyboard;
RAWHID hid;
}
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWINPUT
{
RAWINPUTHEADER header;
MyUnion2 myUnion2;
}
/*
typedef struct tagRAWINPUTDEVI CELIST {
HANDLE hDevice;
DWORD dwType;
} RAWINPUTDEVICEL IST, *PRAWINPUTDEVIC ELIST;
*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWINPUTDEVICEL IST // must use struct instead of class
{
public IntPtr Device;
public int Type;
}
/*typedef struct tagRID_DEVICE_I NFO_MOUSE {
DWORD dwId;
DWORD dwNumberOfButto ns;
DWORD dwSampleRate;
} RID_DEVICE_INFO _MOUSE, *PRID_DEVICE_IN FO_MOUSE;*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RID_DEVICE_INFO _MOUSE
{
public int dwId;
public int dwNumberOfButto ns;
public int dwSampleRate;
}
/*typedef struct tagRID_DEVICE_I NFO_KEYBOARD {
DWORD dwType;
DWORD dwSubType;
DWORD dwKeyboardMode;
DWORD dwNumberOfFunct ionKeys;
DWORD dwNumberOfIndic ators;
DWORD dwNumberOfKeysT otal;
} RID_DEVICE_INFO _KEYBOARD, *PRID_DEVICE_IN FO_KEYBOARD;
*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RID_DEVICE_INFO _KEYBOARD
{
public int dwType;
public int dwSubType;
public int dwKeyboardMode;
public int dwNumberOfFunct ionKeys;
public int dwNumberOfIndic ators;
public int dwNumberOfKeysT otal;
}
/*typedef struct tagRID_DEVICE_I NFO_HID {
DWORD dwVendorId;
DWORD dwProductId;
DWORD dwVersionNumber ;
* Top level collection UsagePage and Usage
USHORT usUsagePage;
USHORT usUsage;
} RID_DEVICE_INFO _HID, *PRID_DEVICE_IN FO_HID;
*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct RID_DEVICE_INFO _HID
{
public int dwVendorId;
public int dwProductId;
public int dwVersionNumber ;
// Top level collection UsagePage and Usage
public UInt16 usUsagePage;
public UInt16 usUsage;
}
/*typedef struct tagRID_DEVICE_I NFO {
DWORD cbSize;
DWORD dwType;
union {
RID_DEVICE_INFO _MOUSE mouse;
RID_DEVICE_INFO _KEYBOARD keyboard;
RID_DEVICE_INFO _HID hid;
};
} RID_DEVICE_INFO , *PRID_DEVICE_IN FO, *LPRID_DEVICE_I NFO;
*/
[ StructLayout( LayoutKind.Sequ ential )]
public struct Union_RID_DEVIC E_INFO
{
RID_DEVICE_INFO _MOUSE mouse;
RID_DEVICE_INFO _KEYBOARD keyboard;
RID_DEVICE_INFO _HID hid;
}
[ StructLayout( LayoutKind.Sequ ential )]
public struct RID_DEVICE_INFO
{
public int cbSize;
public int dwType;
Union_RID_DEVIC E_INFO unionRidDeviceI nfo;
}
--
BP
"PickwickBo b3" wrote:
I am try to marshall the following:
/*typedef struct tagRAWMOUSE
{
USHORT usFlags;
union
{
ULONG ulButtons;
struct
{
USHORT usButtonFlags;
USHORT usButtonData;
};
};
ULONG ulRawButtons;
LONG lLastX;
LONG lLastY;
ULONG ulExtraInformat ion;
} RAWMOUSE, *PRAWMOUSE, *LPRAWMOUSE;*/
To the following in C#:
[ StructLayout( LayoutKind.Sequ ential )]
public struct ButtonFlagsData
{
public UInt16 usButtonFlags;
public UInt16 usButtonData;
}
[ StructLayout( LayoutKind.Sequ ential )]
public struct MyUnion
{
public UInt32 ulButtons;
ButtonFlagsData buttonFlagsData ;
}
[ StructLayout( LayoutKind.Sequ ential )]
public struct RAWMOUSE
{
public UInt16 Flags;
MyUnion myUnion;
public UInt32 RawButtons;
public Int32 LastX;
public Int32 LastY;
public UInt32 ExtraInformatio n;
}
Is that correct?? If not can you suggest the correct formation?? Thanks.
--
BP