duanjong
驱动中牛
驱动中牛
  • 注册日期2003-03-10
  • 最后登录2006-01-18
  • 粉丝0
  • 关注0
  • 积分31分
  • 威望5点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
阅读:3116回复:3

为什么SetupDiEnumDeviceInterfaces返回值总是零?GetLastError()是ERROR_NO_MORE_ITEMS?谢谢

楼主#
更多 发布于:2004-09-06 18:13
void CUsbtestDlg::OnInitUsb()
{
// TODO: Add your control notification handler code here
HDEVINFO HardwareDeviceInfo;
int j;
SP_INTERFACE_DEVICE_DATA deviceInfoData;
int NumberDevices;
HardwareDeviceInfo = SetupDiGetClassDevs(
(LPGUID)&GUID_CLASS_U_BULK,//{6bdd1fc6-810f-11d0-bec7-08002be2092f}
NULL,
NULL,
(DIGCF_PRESENT|DIGCF_INTERFACEDEVICE)
);
if( INVALID_HANDLE_VALUE == HardwareDeviceInfo)
{
lLastError = ::GetLastError();
AfxMessageBox("Get Device Class Failed");
}
else
{
AfxMessageBox("Get Device Class Success");
}

NumberDevices = 21;
deviceInfoData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA);
for(int i=0;i < NumberDevices;i++)
{
j = SetupDiEnumDeviceInterfaces(HardwareDeviceInfo,
0,
(LPGUID)&GUID_CLASS_U_BULK,
i,
&deviceInfoData);
}

if((!j)&&(::GetLastError() == ERROR_NO_MORE_ITEMS))
AfxMessageBox(" No Matched Device ");
else
AfxMessageBox(" Find Matched Device ");

PSP_INTERFACE_DEVICE_DETAIL_DATA functionClassDeviceData = NULL;
ULONG predictedLength = 0;
ULONG requiredLength = 0;
SetupDiGetInterfaceDeviceDetail(HardwareDeviceInfo,
&deviceInfoData,
NULL,
0,
&requiredLength,
NULL);
predictedLength = requiredLength;

functionClassDeviceData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(predictedLength);
lLastError = ::GetLastError();
if(!SetupDiGetInterfaceDeviceDetail(HardwareDeviceInfo,
&deviceInfoData,
functionClassDeviceData,
predictedLength,
&requiredLength,
NULL))
{
lLastError = ::GetLastError();
AfxMessageBox("Get Device Path Failed");
//return 0;//INVALID_HANDLE_VALUE;
}
else
{
AfxMessageBox("Get Device Path Success");
}

HANDLE hDeviceHandle;
hDeviceHandle = CreateFile(
functionClassDeviceData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,0,
NULL
);
if(hDeviceHandle == INVALID_HANDLE_VALUE)
{
lLastError = ::GetLastError();
AfxMessageBox("Get Device Handle Failed");
}
else
{
AfxMessageBox("Get Device Handle Success");
}

char completeDeviceName[256] ="";
strcat(completeDeviceName,functionClassDeviceData->DevicePath);
strcat(completeDeviceName,"\\PIPE2");
hIntfHandle = CreateFile(
completeDeviceName,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if(hIntfHandle == INVALID_HANDLE_VALUE)
{
lLastError = ::GetLastError();
AfxMessageBox("Get Interface Handle Failed");
}
else
{
AfxMessageBox("Get Interface Handle Success");
}

// return 0;
}
angelzhen
驱动牛犊
驱动牛犊
  • 注册日期2004-07-22
  • 最后登录2004-11-05
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-09-22 09:11
我也遇上了同样的问题.希望各位高手帮帮忙.
另外我发现调用SetupDiEnumDeviceInfo函数可以找到我的usb设备.
请问SetupDiEnumDeviceInfo与SetupDiEnumDeviceInterfaces有什么区别?是不是一个是device ?另一个是interface?但是device 与interface又有什么区别?
新手
duanjong
驱动中牛
驱动中牛
  • 注册日期2003-03-10
  • 最后登录2006-01-18
  • 粉丝0
  • 关注0
  • 积分31分
  • 威望5点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2004-09-07 13:42
是的,因为我的设备已开始使用,通信还可以,我现在想测试一下。但是得不到设备的 句柄。还可能是其他问题吗?
histogram
驱动牛犊
驱动牛犊
  • 注册日期2004-08-28
  • 最后登录2006-09-07
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2004-09-07 13:12
确定你的设备和驱动正常工作/
游客

返回顶部