资源简介
HID USB通信的动态库,根据ProductID和VendorID来识别设备,可以直接调用使用;
压缩包包含源代码,VC++开发,应用于Window系统中程序和HID设备通信;
代码片段和文件信息
// HIDUSB.cpp : 定义 DLL 应用程序的入口点。
//
#include “stdafx.h“
#include “hidusb.h“
extern “C“ {
// Declare the C libraries used
#include “setupapi.h“ // Must link in setupapi.lib
#include “hidsdi.h“ // Must link in hid.lib
}
#ifdef _MANAGED
#pragma managed(push off)
#endif
BOOL APIENTRY DllMain( HMODULE hModule
DWORD ul_reason_for_call
LPVOID lpReserved
)
{
return TRUE;
}
BOOL __stdcall DLLAPI SearchHIDDev(unsigned short nVendorID unsigned short nProductID int * piDevNum char * acInfo){
struct _GUID GUID;
int iRetErr;
SP_INTERFACE_DEVICE_DATA DeviceInterfaceData;
HANDLE PnPHandle=NULLHIDHandle=NULL;
struct {
DWORD cbSize;
char DevicePath[256];
} FunctionClassDeviceData;
HIDD_ATTRIBUTES HIDAttributes;
SECURITY_ATTRIBUTES SecurityAttributes;
int Device;
ULONG BytesReturned;
bool Success;
* piDevNum = 0;
// Initialize the GUID array and setup the security attributes for Win2000
HidD_GetHidGuid(&GUID);
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = false;
// Get a handle for the Plug and Play node and request currently active devices
PnPHandle = SetupDiGetClassDevs(&GUID NULL NULL DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
if (int(PnPHandle) == -1) {
strcpy(acInfo“Could not attach to PnP node.“);//printf(“Could not attach to PnP node“);
iRetErr = GetLastError();
return iRetErr;
}
// Lets look for a maximum of 22 Devices
for (Device = 0; Device < 22; Device++) {
// Initialize our data
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);
// Is there a device at this table entry
Success = SetupDiEnumDeviceInterfaces(PnPHandle NULL &GUID Device &DeviceInterfaceData);
if (Success) {
// There is a device here get it‘s name
FunctionClassDeviceData.cbSize = 5;
Success = SetupDiGetDeviceInterfaceDetail(PnPHandle &DeviceInterfaceData
(PSP_INTERFACE_DEVICE_DETAIL_DATA)&FunctionClassDeviceData 256 &BytesReturned NULL);
if (!Success) {
strcpy(acInfo“Could not find the system name for this device.“);
iRetErr = GetLastError();
if(PnPHandle)
SetupDiDestroyDeviceInfoList(PnPHandle);
return iRetErr;
}
// Can now open this device
HIDHandle = CreateFile(FunctionClassDeviceData.DevicePath GENERIC_READ|GENERIC_WRITE
FILE_SHARE_READ|FILE_SHARE_WRITE &SecurityAttributes OPEN_EXISTING 0 NULL);
if (HIDHandle == INVALID_HANDLE_VALUE)
sprintf(acInfo“Could not open HID #%d Errorcode = %d\n“ Device GetLastError());
else {
// Get the information about this HID
Success = HidD_GetAttributes(HIDHandle &HIDAttributes);
if (!Success) {
strcpy(acInfo“Could not get HID attributes.“);
iRetErr = GetLastError();
if(PnPHandle)
SetupDiDestroyDeviceInfoList(PnPHa
- 上一篇:网络主机的存活性探测系统设计与实现VC
- 下一篇:车牌识别与定位C++
相关资源
- usb2187数据采集卡的程序
- USB3.0发送与接收数据c++版本
- USB 3.0编程宝典.pdf
- libusb bulk传输 STM32上位机程序
- STM32 USB BULK
- VC++ USB及串口通信工程源码
- 基于winusb的上位机与USB的通信
- Quectel_WCDMALTE_Linux_USB_Driver_User_Guide_V
- USB HID STM32 开发资料全集
- C++的USB上位机程序.zip
- MFC读取USB接口硬盘固件、序列号、型
- C#实时监测usb设备的插拔情况,winfo
- VC++ USB接口编程(代码)
- c++usb端口访问
- C++ USB HID
- Project1.rar
- USB 通讯 libusb-win32
- 周立功USBCAN函数库ControlCAN.dll最新版
- VC++编写USB接口通信程序
- c语言程序实现PC端通过USB端口与单片
- 即时检测USB设备插拔
- 用C语言编写的usb自动识别程序
- VC++ HIDAPI实现USB数据读写
- USB键盘驱动C++
- hid鼠标和键盘
- 基于MFC编写的读写USB_HID设备数据程序
- hid.lib setupapi.lib 等HID开发相关的库和
- usb_hid_vc++6.0读写设备源码
- Winsoft HID v1.6 for Delphi C++ Builder 5 - 1
- DBC的C++解析源码
评论
共有 条评论