//USB Connect
#include "Dbt.h"
#include "usbiodef.h"
#include
#include
#include
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, // vertical position of window
0, // window width
0, // window height
NULL, // handle to parent or owner window
NULL, // handle to menu or child-window identifier
hInstance, // handle to application instance
NULL); // pointer to window-creation data
::ShowWindow (g_hwndConnDev, SW_HIDE);
DEV_BROADCAST_DEVICEINTERFACE broadcastInterface;
//SECURITY_ATTRIBUTES sec_attr;
//SECURITY_DESCRIPTOR sd;
ZeroMemory( &broadcastInterface,sizeof(broadcastInterface));
broadcastInterface.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
broadcastInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
memcpy( &(broadcastInterface.dbcc_classguid),
&(GUID_CLASS_USB_DEVICE),
sizeof(struct _GUID));
HANDLE Hhanm_hNotifyDevHandle = RegisterDeviceNotification((HANDLE)g_hwndConnDev,
&broadcastInterface,
DEVICE_NOTIFY_WINDOW_HANDLE );
// Now register for Hub notifications.
memcpy( &(broadcastInterface.dbcc_classguid),
&(GUID_CLASS_USBHUB),
sizeof(struct _GUID));
HANDLE m_hNotifyHubHandle = RegisterDeviceNotification((HANDLE)g_hwndConnDev,
&broadcastInterface,
DEVICE_NOTIFY_WINDOW_HANDLE);
return TRUE;
}
LRESULT CALLBACK ConnWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
PDEV_BROADCAST_HDR pDevBcastHdr;
PDEV_BROADCAST_DEVICEINTERFACE pDevBcastDevIface;
char * lpTmp=0;
switch (msg)
{
case WM_CREATE:
break;
case WM_DEVICECHANGE:
switch (wParam)
{
case DBT_DEVICEARRIVAL:
case DBT_DEVICEREMOVECOMPLETE:
pDevBcastHdr = (PDEV_BROADCAST_HDR)lParam;
if (! pDevBcastHdr || pDevBcastHdr->dbch_devicetype != DBT_DEVTYP_DEVICEINTERFACE)
break;
pDevBcastDevIface = (PDEV_BROADCAST_DEVICEINTERFACE)lParam;
// Get Vid Pid value
lpTmp = strchr (pDevBcastDevIface->dbcc_name, 'V');
if(lpTmp)
{
lpTmp += 4;
if(!memcmp(lpTmp,g_cVID,4))
{
if (lpTmp = strchr(lpTmp, 'P'))
{
lpTmp += 4;
if(!memcmp(lpTmp,g_cPID_RGB,4) || !memcmp(lpTmp,g_cPID_Infrared,4))
{
//2USB connect status
if(wParam == DBT_DEVICEREMOVECOMPLETE)
{
if(g_pCameraMsgDlg)
{
g_pCameraMsgDlg->WriteStatusMemory(1);
}
}
else if(wParam == DBT_DEVICEARRIVAL)
{
//2USB all Connect
if(GetCameraUSB())
{
if(g_pCameraMsgDlg)
{
g_pCameraMsgDlg->WriteStatusMemory(0);
}
}
}
}
}
}
}
//sscanf ((const char *)lpTmp, "%x", &wVendorId);
break;
}
break;
case WM_CLOSE:
{
DestroyWindow(g_hwndConnDev);
break;
}
case WM_DESTROY:
{
// Wait all Device DLL are closed !!!
PostQuitMessage(0);
}
break;
default:
return DefWindowProc (hwnd, msg, wParam, lParam);
}
return 0;
}