1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "ConsoleApplication3.h"
#include "Setupapi.h"
#include "Usbiodef.h"
#include "stdafx.h"
#include "winusb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// The one and only application object
CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR *argv[], TCHAR *envp[]) {
HDEVINFO pdev;
GUID uusb;
uusb.Data1 = 0xA5DCBF10;
uusb.Data2 = 0x6530;
uusb.Data3 = 0x11D2;
uusb.Data4[0] = 0x90;
uusb.Data4[1] = 0x1F;
uusb.Data4[2] = 0x00;
uusb.Data4[3] = 0xC0;
uusb.Data4[4] = 0x4F;
uusb.Data4[5] = 0xB9;
uusb.Data4[6] = 0x51;
uusb.Data4[7] = 0xED;
SP_DEVICE_INTERFACE_DATA intadata;
ULONG rulength = 0;
PSP_DEVICE_INTERFACE_DETAIL_DATA dutaildata;
dutaildata = NULL;
ULONG lunghth;
HANDLE rr;
PWINUSB_INTERFACE_HANDLE usbhan = 0;
pdev = SetupDiGetClassDevs(&GUID_DEVINTERFACE_USB_DEVICE, NULL, NULL,
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
intadata.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
SetupDiEnumDeviceInterfaces(pdev, NULL, &GUID_DEVINTERFACE_USB_DEVICE, 0,
&intadata);
SetupDiGetDeviceInterfaceDetail(pdev, &intadata, NULL, 0, &rulength, NULL);
dutaildata =
(PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED, rulength);
dutaildata->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
lunghth = rulength;
SetupDiGetDeviceInterfaceDetail(pdev, &intadata, dutaildata, lunghth,
&rulength, NULL);
rr = CreateFile(dutaildata->DevicePath, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, NULL);
WinUsb_Initialize(rr, usbhan);
int nRetCode = 0;
HMODULE hModule = ::GetModuleHandle(NULL);
if (hModule != NULL) {
// initialize MFC and print and error on failure
if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0)) {
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: MFC initialization failed\n"));
nRetCode = 1;
} else {
// TODO: code your application's behavior here.
}
} else {
// TODO: change error code to suit your needs
_tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
nRetCode = 1;
}
return nRetCode;
}
| |