Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i want to get device name of HID device using GetRawInputDeviceInfo method of User32.dll. And i am getting window handle from lparam of WndProc Message as mentioned in GetRawInputDeviceInfo function (Windows)[^] but it give pcbSize=0 always.

C#
protected override void WndProc(ref Message m)
        {

            if (m.Msg == 0xFF)
            {
                string deviceName = GetDeviceName(m.LParam);
            }
         }

public string GetDeviceName(IntPtr DeviceHandle)
{
   uint pcbSize = 0;
   string deviceName="";
   GetRawInputDeviceInfo(DeviceHandle, RIDI_DEVICENAME, IntPtr.Zero, ref pcbSize);
   if (pcbSize > 0)
      {
        IntPtr pData = Marshal.AllocHGlobal((int)pcbSize);
        GetRawInputDeviceInfo(DeviceHandle, RIDI_DEVICENAME, pData, ref pcbSize);
        deviceName = Marshal.PtrToStringAnsi(pData);
        Marshal.FreeHGlobal(pData);
        }
   return deviceName;
}


What i am doing wrong here ?
I want to get device name from WndProc message simply.
Posted
Updated 30-Nov-12 20:41pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900