mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-14 15:46:19 +00:00
WinUSB API implemented!!
This commit is contained in:
116
test/main.cpp
116
test/main.cpp
@@ -1,3 +1,4 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS 1
|
||||
|
||||
#if __APPLE__
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
@@ -10,7 +11,6 @@
|
||||
#include <windows.h>
|
||||
#include <initguid.h>
|
||||
#include <Usbiodef.h>
|
||||
#include <Dbt.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
@@ -61,6 +61,86 @@ public:
|
||||
|
||||
}
|
||||
|
||||
#if _WIN32
|
||||
|
||||
/* This simple 'test' console app needs a full windows
|
||||
* message loop for receiving device connection events
|
||||
*/
|
||||
static const DEV_BROADCAST_DEVICEINTERFACE_A HOTPLUG_CONF =
|
||||
{
|
||||
sizeof(DEV_BROADCAST_DEVICEINTERFACE_A),
|
||||
DBT_DEVTYP_DEVICEINTERFACE,
|
||||
0,
|
||||
GUID_DEVINTERFACE_USB_DEVICE
|
||||
};
|
||||
|
||||
LRESULT CALLBACK WindowProc(
|
||||
_In_ HWND hwnd,
|
||||
_In_ UINT uMsg,
|
||||
_In_ WPARAM wParam,
|
||||
_In_ LPARAM lParam
|
||||
)
|
||||
{
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
/* Register hotplug notification with windows */
|
||||
RegisterDeviceNotificationA(hwnd, (LPVOID)&HOTPLUG_CONF, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
return 0;
|
||||
|
||||
case WM_DEVICECHANGE:
|
||||
return boo::CDeviceFinder::winDevChangedHandler(wParam, lParam);
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
int APIENTRY wWinMain(
|
||||
_In_ HINSTANCE hInstance,
|
||||
_In_ HINSTANCE,
|
||||
_In_ LPTSTR,
|
||||
_In_ int
|
||||
)
|
||||
{
|
||||
AllocConsole();
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
|
||||
WNDCLASS wndClass =
|
||||
{
|
||||
0,
|
||||
WindowProc,
|
||||
0,
|
||||
0,
|
||||
hInstance,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
L"BooTestWindow"
|
||||
};
|
||||
|
||||
RegisterClassW(&wndClass);
|
||||
|
||||
boo::CTestDeviceFinder finder;
|
||||
finder.startScanning();
|
||||
|
||||
HWND hwnd = CreateWindowW(L"BooTestWindow", L"BooTest", WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
/* Pump messages */
|
||||
MSG msg = {0};
|
||||
while (GetMessage(&msg, hwnd, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
@@ -77,40 +157,10 @@ int main(int argc, char** argv)
|
||||
|
||||
#if __APPLE__
|
||||
CFRunLoopRun();
|
||||
#elif _WIN32
|
||||
|
||||
/* Register hotplug notification with windows */
|
||||
DEV_BROADCAST_DEVICEINTERFACE_A hotplugConf =
|
||||
{
|
||||
sizeof(DEV_BROADCAST_DEVICEINTERFACE_A),
|
||||
DBT_DEVTYP_DEVICEINTERFACE,
|
||||
0,
|
||||
GUID_DEVINTERFACE_USB_DEVICE
|
||||
};
|
||||
HWND consoleWnd = GetConsoleWindow();
|
||||
HDEVNOTIFY notHandle = RegisterDeviceNotificationA(consoleWnd, &hotplugConf, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
|
||||
MSG recvMsg;
|
||||
while (GetMessage(&recvMsg, consoleWnd, 0, 0))
|
||||
{
|
||||
printf("MSG: %d\n", recvMsg.message);
|
||||
switch (recvMsg.message)
|
||||
{
|
||||
case WM_DEVICECHANGE:
|
||||
printf("DEVICECHANGE!!\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
TranslateMessage(&recvMsg);
|
||||
DispatchMessage(&recvMsg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
while (true) {sleep(1);}
|
||||
#endif
|
||||
|
||||
//delete ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user