Applies to: desktop apps only
Retrieves the raw input from the specified device.
Syntax
UINT WINAPI GetRawInputData( __in HRAWINPUT hRawInput, __in UINT uiCommand, __out_opt LPVOID pData, __inout PUINT pcbSize, __in UINT cbSizeHeader );
Parameters
- hRawInput [in]
-
Type: HRAWINPUT
A handle to the RAWINPUT structure. This comes from the lParam in WM_INPUT.
- uiCommand [in]
-
Type: UINT
The command flag. This parameter can be one of the following values.
Value Meaning - RID_HEADER
- 0x10000005
Get the header information from the RAWINPUT structure.
- RID_INPUT
- 0x10000003
Get the raw data from the RAWINPUT structure.
- pData [out, optional]
-
Type: LPVOID
A pointer to the data that comes from the RAWINPUT structure. This depends on the value of uiCommand. If pData is NULL, the required size of the buffer is returned in *pcbSize.
- pcbSize [in, out]
-
Type: PUINT
The size, in bytes, of the data in pData.
- cbSizeHeader [in]
-
Type: UINT
The size, in bytes, of the RAWINPUTHEADER structure.
Return value
Type: UINT
If pData is NULL and the function is successful, the return value is 0. If pData is not NULL and the function is successful, the return value is the number of bytes copied into pData.
If there is an error, the return value is (UINT)-1.
Remarks
GetRawInputData gets the raw input one RAWINPUT structure at a time. In contrast, GetRawInputBuffer gets an array of RAWINPUT structures.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
See also
- Reference
- GetRawInputBuffer
- RAWINPUT
- RAWINPUTHEADER
- Conceptual
- Raw Input
Send comments about this topic to Microsoft
Build date: 3/6/2012
Public Declare Function GetRawInputData Lib "user32.dll" ( _
ByVal hRawInput As IntPtr, _
ByVal uiCommnad As GetRawInputDataCommand, _
ByVal pData As IntPtr, _
ByRef pcbSize As UInteger, _
ByVal cbSizeHeader As UInteger) _
As Integer
This function must be called twice. 1st to determine number of bytes that must be allocated, second to populate alocated unmanaged memory. Then data must be got from unmanaged to managed memory and unmaneged memory must be freed.Public Enum GetRawInputDataCommand As UInteger
RID_INPUT = &H10000003
RID_HEADER = &H10000005
End Enum
Dim Size% = 0
'Determine size to be alocated
Dim ret = GetRawInputData(hRawInput, GetRawInputDataCommand.RID_INPUT, IntPtr.Zero, Size, Marshal.SizeOf(GetType(RAWINPUTHEADER)))
If ret = -1 Then Throw New API.Win32APIException
Dim SizeToAllocate = Math.Max(Size, Marshal.SizeOf(GetType(API.RawInput.RAWINPUT_Marshalling)))
Dim pData As IntPtr = Marshal.AllocHGlobal(SizeToAllocate)
Try'Populate alocated memory
ret = GetRawInputData(hRawInput,GetRawInputDataCommand.RID_INPUT, pData, SizeToAllocate, Marshal.SizeOf(GetType(RAWINPUTHEADER)))
If ret = -1 Then Throw New System.ComponentModel.Win32Exception
Dim Header As RAWINPUTHEADER = Marshal.PtrToStructure(pData, GetType(API.RawInput.RAWINPUTHEADER)) 'RAWINPUT starts with RAWINPUTHEADER, so we can do this
Select Case Header.dwType
Case DeviceTypes.RIM_TYPEHID 'As described on page of RAWHID, RAWHID needs special treatement
Dim raw As RAWINPUT_Marshalling = Marshal.PtrToStructure(pData, GetType(RAWINPUT_Marshalling)) 'Get marshalling version, it contains information about block size and count
Dim raw2 As API.RAWINPUT_NonMarshalling'Do some copying
raw2.header = raw.header
raw2.hid.dwCount = raw.hid.dwCount
raw2.hid.dwSizeHid = raw.hid.dwSizeHid
ReDim raw2.hid.bRawData(raw.hid.dwCount * raw.hid.dwSizeHid - 1) 'Allocate array'Populate the array
Marshal.Copy(pData.ToInt64 + Marshal.SizeOf(GetType(RAWINPUTHEADER)) + Marshal.SizeOf(GetType(RAWHID_Marshalling)), raw2.hid.bRawData, 0, raw.hid.dwCount * raw.hid.dwSizeHid)
Return raw2
Case Else 'No additional processing is needed
Return DirectCast(Marshal.PtrToStructure(pData, GetType(RAWINPUT_Marshalling)), RAWINPUT_Marshalling)
End Select
Finally
Marshal.FreeHGlobal(pData)
End Try
Note: This example returns different data type for RIM_TYPEHID and other types. You should consider do some casting.