//USB Connect
#include "Dbt.h"
#include "usbiodef.h"
#include <winioctl.h>
#include <setupapi.h>
#include <initguid.h>
DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE,
0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED);
DEFINE_GUID(GUID_DEVINTERFACE_USB_HUB, 0xf18a0e88, 0xc30c, 0x11d0, 0x88, 0x15, 0x00, \
0xa0, 0xc9, 0x06, 0xbe, 0xd8);
#define GUID_CLASS_USBHUB GUID_DEVINTERFACE_USB_HUB
#define GUID_CLASS_USB_DEVICE GUID_DEVINTERFACE_USB_DEVICE
#pragma comment(lib, "hid.lib")
#pragma comment(lib, "setupapi.lib")
#pragma comment(lib, "imagehlp.lib")
BOOL CCameraMsgDlg::OnDeviceConnect()
{
HINSTANCE hInstance = (HINSTANCE)GetWindowWord(this->m_hWnd, GWL_HINSTANCE);
WNDCLASS wndclass;
wndclass.style = 0;
wndclass.lpfnWndProc = ConnWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = NULL;
wndclass.hCursor = NULL;
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "InspurDeviceWnd";
RegisterClass (&wndclass);
g_hwndConnDev = CreateWindow(wndclass.lpszClassName, // pointer to registered class name
"HeHe Device Window", // pointer to window name
0,// window style
0, // horizontal position of window
0,
USB设备连接监控与VIDPID获取

该代码段实现了一个Windows应用程序,用于监听USB设备的插入和移除事件,特别是那些具有特定VID和PID的设备。当USB设备连接或断开时,程序会根据WM_DEVICECHANGE消息处理函数进行相应操作,识别并处理设备的VID和PID,更新状态。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



