Vanara icon indicating copy to clipboard operation
Vanara copied to clipboard

[Bug] GetRawInputDeviceInfo can not use CharSet = CharSet.Auto

Open emako opened this issue 4 months ago • 0 comments

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);

emako avatar Feb 06 '24 09:02 emako