我从网上下载了一个testusb的程序 http://www.vckbase.com/code/winsys/driver/testusb.rar
用来枚举usb设备的一个测试程序,需要DDK配合编译
我用vs2005+ddk 就是编译不过
网上解决的错误的办法我都试过了:
不要跟我说我没加库 我加了hid.lib setupapi.lib
不要说我没用extern引用头文件 我用了
extern "C" {
#include "hidsdi.h" //DDK文件
#include <setupapi.h>
}
不要说我没试着注释掉某个结构体,我也试了 就是编译不过
1>d:\winddk\7600.16385.0\inc\api\usbiodef.h(204) : error C2065: 'PASSIVE_LEVEL' : undeclared identifier
1>d:\winddk\7600.16385.0\inc\api\usbiodef.h(207) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\winddk\7600.16385.0\inc\api\usbiodef.h(207) : error C2199: syntax error : found 'void (' at global scope (was a declaration intended?)
1>d:\winddk\7600.16385.0\inc\api\hidpi.h(303) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\winddk\7600.16385.0\inc\api\hidpi.h(303) : error C2374: '__drv_maxIRQL' : redefinition; multiple initialization
1> d:\winddk\7600.16385.0\inc\api\usbiodef.h(204) : see declaration of '__drv_maxIRQL'
1>d:\winddk\7600.16385.0\inc\api\hidpi.h(303) : error C2146: syntax error : missing ';' before identifier 'NTSTATUS
这是错误片段
如果有可编译的工程 打包发我也行 多谢啦!
------最佳解决方案--------------------
#include "stdafx.h"
#include <setupapi.h>
#include <devguid.h>
#include <regstr.h>
#pragma comment (lib, "setupapi.lib")
BOOL GetDeviceInfo(void);
int _tmain(int argc, _TCHAR* argv[])
{
GetDeviceInfo();
system("pause");
return 0;
}
BOOL GetDeviceInfo(void)
{
HDEVINFO m_hDevInfo;
SP_DEVINFO_DATA m_stuDevInfoData;
m_hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_USB, NULL, NULL, DIGCF_PRESENT);
if (m_hDevInfo == INVALID_HANDLE_VALUE
------其他解决方案--------------------
m_hDevInfo == NULL)
{
wprintf(_T("Fail to get USB device handle!"));
return FALSE;
}
else
{
m_stuDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
int nIndex(0);
DWORD dwBufferSize(0);
TCHAR* szInstanceId(NULL);
while (SetupDiEnumDeviceInfo(m_hDevInfo, ++nIndex, &m_stuDevInfoData))
{
if (!SetupDiGetDeviceInstanceId(m_hDevInfo, &m_stuDevInfoData, NULL, 0, &dwBufferSize))
{
szInstanceId = new TCHAR[dwBufferSize];
}
if (SetupDiGetDeviceInstanceId(m_hDevInfo, &m_stuDevInfoData, szInstanceId, dwBufferSize, NULL))
{
wprintf(_T("Result:\n%s\n"), szInstanceId);
}
else
{
wprintf(_T("Fail to get USB device information!"));
delete [] szInstanceId;
return FALSE;
}
if (szInstanceId != NULL)
{
delete [] szInstanceId;
}
}