gpt4 book ai didi

hid - 在 VC++ 中使用 PID 和 VID 函数检测 USB 设备的问题

转载 作者:行者123 更新时间:2023-12-05 04:18:57 26 4
gpt4 key购买 nike

我正在尝试开发一个 API 来检测 USB 设备是否已连接到我的 USB 端口。我使用 MAX3420e 作为我的 USB 设备,它通过 MSP430 uC 进行控制。我对 VC++ 的知识几乎为零,而且我一直在阅读 USB complete,其中提到了有关如何检测 USB 设备及其相关功能的示例代码......我写了一个小代码来查找连接的 USB 设备的 PID 和 VID...但是,我收到以下错误:

错误 LNK2019:未解析的外部符号“bool __cdecl HidD_GetAttributes(void *,struct _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;
}

最佳答案

setupapi.lib 作为链接器输入选项卡中的附加依赖项。

关于hid - 在 VC++ 中使用 PID 和 VID 函数检测 USB 设备的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6204777/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com