yawijaya
Member level 2

- Joined
- Aug 18, 2009
- Messages
- 42
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- New Freedom, PA-USA
- Activity points
- 1,625
I am developing a Windows application to communicate with a USB HID. I've got the firmware working on the device, and windows also recognize it without problem. I am now stumbled on how my software will be able to find the correct device to communicate with. I've read several codes online and pretty much they all refer to the same method of finding the correct device. However, there seems to be a part on the code that is giving me trouble, which is the calling of SetupDiGetDeviceInterfaceDetail function. Here's the piece of the code:
HidD_GetHidGuid(&HidGuid);
hDevInfo=SetupDiGetClassDevs
(&HidGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
devInfoData.cbSize=sizeof(devInfoData);
LastDevice=FALSE;
Result=SetupDiEnumDeviceInterfaces
(hDevInfo,
0,
&HidGuid,
MemberIndex,
&devInfoData);
if(Result != 0)
{
Result=SetupDiGetDeviceInterfaceDetail
(hDevInfo,
&devInfoData,
NULL,
0,
&Length,
NULL);
detailData=(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);
detailData->cbSize=sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
Memo->Text= detailData->cbSize;
Result=SetupDiGetDeviceInterfaceDetail
(hDevInfo,
&devInfoData,
detailData,
Length,
&Required,
NULL);
Result=GetLastError();
Memo->Lines->Add(Result);
}
The GetLastError() would return error code 1784, which is "The supplied user buffer is not valid for the requested operation." Is this error expected? If not, anybody has any suggestion of what I should do?Thanks
HidD_GetHidGuid(&HidGuid);
hDevInfo=SetupDiGetClassDevs
(&HidGuid,
NULL,
NULL,
DIGCF_PRESENT | DIGCF_INTERFACEDEVICE);
devInfoData.cbSize=sizeof(devInfoData);
LastDevice=FALSE;
Result=SetupDiEnumDeviceInterfaces
(hDevInfo,
0,
&HidGuid,
MemberIndex,
&devInfoData);
if(Result != 0)
{
Result=SetupDiGetDeviceInterfaceDetail
(hDevInfo,
&devInfoData,
NULL,
0,
&Length,
NULL);
detailData=(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);
detailData->cbSize=sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
Memo->Text= detailData->cbSize;
Result=SetupDiGetDeviceInterfaceDetail
(hDevInfo,
&devInfoData,
detailData,
Length,
&Required,
NULL);
Result=GetLastError();
Memo->Lines->Add(Result);
}
The GetLastError() would return error code 1784, which is "The supplied user buffer is not valid for the requested operation." Is this error expected? If not, anybody has any suggestion of what I should do?Thanks