Vanara
Vanara copied to clipboard
[Bug] GetRawInputDeviceInfo can not use CharSet = CharSet.Auto
Error Code:
// CharSet = CharSet.Auto will get the half pcbSize size
[DllImport(Lib.User32, SetLastError = true, CharSet = CharSet.Auto)]
[PInvokeData("winuser.h", MSDNShortId = "")]
public static extern uint GetRawInputDeviceInfo(HANDLE hDevice, uint uiCommand, IntPtr pData, ref uint pcbSize);
And then Marshal.PtrToStringAuto will get the error device name or some time will make application crash when in Chinese OS.
Like this issuse https://github.com/dahall/Vanara/issues/428
I use following code to fix it.
correct code:
[DllImport("User32.dll", SetLastError = true)]
internal static extern uint GetRawInputDeviceInfo(IntPtr hDevice, RawInputDeviceInfo command, IntPtr pData, ref uint size);