using SetupDiGetDeviceInterfaceDetail

  • Thread starter Thread starter Joe B.
  • Start date Start date
J

Joe B.

Hello,
This is my first attempt at posting to the newsgroup. My apologies if I
have directed this question to the wrong bunch.

I am trying to use SetupDiGetDeviceInterfaceDetail function in order to get
a handle to a USB HID device so that I can open it using CreateFile.
After struggling with this function for a couple of days, I feel that I
finally understand what it does and what I have to provide it. However,
when I run my program, I get an arcane error message which says "the user
supplied buffer is not valid for the requested operation". I called the
function once to get the required size and that worked telling me I needed
170 bytes. I allocated that much TCHAR for the DevicePath buffer. Then I
cast the buffer as the structure called for in the function parameter list.
Can anyone help me figure out what I'm doing wronb? Shall I post my source
code? Can you point me to a reference that might help me out.
Thanks,
Joe
 
Joe B. said:
Hello,
This is my first attempt at posting to the newsgroup. My apologies if I
have directed this question to the wrong bunch.

I am trying to use SetupDiGetDeviceInterfaceDetail function in order to
get
a handle to a USB HID device so that I can open it using CreateFile.
After struggling with this function for a couple of days, I feel that I
finally understand what it does and what I have to provide it. However,
when I run my program, I get an arcane error message which says "the user
supplied buffer is not valid for the requested operation". I called the
function once to get the required size and that worked telling me I needed
170 bytes. I allocated that much TCHAR for the DevicePath buffer. Then I
cast the buffer as the structure called for in the function parameter
list.
Can anyone help me figure out what I'm doing wronb? Shall I post my
source
code? Can you point me to a reference that might help me out.

Make sure that you properly initialize the buffer, setting
cbSize = sizeof (SP_DEVICE_INTERFACE_DETAIL_DATA)
and not the allocated size, because the cbSize field is used by Win32 API as
a kind of version number. The fourth parameter should be the allocated size
(170).
 
Back
Top