1
我想開發一個API來檢測USB設備是否已連接到我的USB端口。我使用MAX3420e作爲我的USB設備,通過MSP430 uC進行控制。 我幾乎沒有VC++的知識,而且我一直在閱讀USB complete,其中提到了一個關於如何檢測USB設備及其相關功能的示例代碼...我寫了一個小代碼,它會查找PID和連接的USB設備的VID ......不過,我收到以下錯誤:在VC++中使用PID和VID函數檢測USB設備的問題
錯誤LNK2019:無法解析的外部符號 「布爾__cdecl HidD_GetAttributes(void *的,結構_HIDD_ATTRIBUTES *)」(HidD_GetAttributes @@ YA_NPAXPAU_HIDD_ATTRIBUTES @ @@ Z)功能_wmain引用
任何人都可以請讓我知道我會去哪裏錯?謝謝...
// usb-complete-3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "winusb.h"
#include "Usb100.h"
#include "Setupapi.h"
HANDLE hDevInfo;
GUID HidGuid;
SP_DEVICE_INTERFACE_DATA devInfoData;
int MemberIndex;
LONG Result;
//SP_DEVICE_INTERFACE_DATA devInfoData;
HANDLE DeviceHandle;
ULONG Length;
ULONG Required;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
typedef struct _HIDD_ATTRIBUTES {
ULONG Size;
USHORT VendorID;
USHORT ProductID;
USHORT VersionNumber; }
HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
void HidD_GetHidGuid(OUT LPGUID HidGuid)
{};
void *SetupDiGetClassDevs(
IN LPGUID ClassGuid, OPTIONAL
IN PCTSTR Enumerator, OPTIONAL
IN HWND hwndParent, OPTIONAL
IN DWORD Flags){return (0);}
void *SetupDiEnumDeviceInterfaces(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData, OPTIONAL
IN LPGUID InterfaceClassGuid,
IN DWORD MemberIndex,
OUT PSP_DEVICE_INTERFACE_DATA
DeviceInterfaceData){return (0);}
bool
HidD_GetAttributes(IN HANDLE HidDeviceObject,OUT PHIDD_ATTRIBUTES Attributes) ;
WINSETUPAPI
BOOL
WINAPI
SetupDiGetDeviceInterfaceDetail(
IN HDEVINFO DeviceInfoSet,
IN PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData,
OUT PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData, OPTIONAL
IN DWORD DeviceInterfaceDetailDataSize,
OUT PDWORD RequiredSize, OPTIONAL
OUT PSP_DEVINFO_DATA DeviceInfoData OPTIONAL
);
int _tmain(int argc, _TCHAR* argv[])
{
while(1)
{
HIDD_ATTRIBUTES Attributes;
HidD_GetHidGuid(&HidGuid);
hDevInfo=SetupDiGetClassDevs (&HidGuid,NULL, NULL,DIGCF_PRESENT|DIGCF_INTERFACEDEVICE); //get the device information
devInfoData.cbSize = sizeof(devInfoData);
SetupDiEnumDeviceInterfaces(hDevInfo,0,&HidGuid,MemberIndex,&devInfoData); // check for the enumerated devices
// The call will return with a "buffer too small" error which can be ignored.
Result = SetupDiGetDeviceInterfaceDetail(hDevInfo,&devInfoData,NULL,0,&Length,NULL);// Allocate memory for the hDevInfo structure, using the returned Length.
detailData =(PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);
// Set cbSize in the detailData structure.
detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);// Call the function again, this time passing it the returned buffer size.
Result = SetupDiGetDeviceInterfaceDetail(hDevInfo,&devInfoData,detailData,Length,&Required, NULL);
// Set the Size member to the number of bytes in the structure.
Attributes.Size = sizeof (Attributes) ;
HidD_GetAttributes(DeviceHandle,&Attributes); // get the PID and VID of the devices connected
}
return 0;
}
有人找出了什麼可能是什麼問題?我真的很感激... @JohnB,非常感謝編輯代碼,我真的無法弄清楚如何輸入代碼,因爲這是我的第一篇文章 – user779825 2011-06-03 16:35:27