Click here to Skip to main content
13,298,361 members (55,273 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.

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

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100