0% found this document useful (0 votes)
41 views2 pages

Win Usb Template

The document describes a sample program that communicates with a USB device using WinUSB. It finds a connected device with a WinUSB driver installed, gets the device descriptor, and prints the vendor ID, product ID, and USB version.

Uploaded by

2243501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views2 pages

Win Usb Template

The document describes a sample program that communicates with a USB device using WinUSB. It finds a connected device with a WinUSB driver installed, gets the device descriptor, and prints the vendor ID, product ID, and USB version.

Uploaded by

2243501
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

LONG __cdecl _tmain(

LONG
Argc,
LPTSTR * Argv
)
/*++
Routine description:
Sample program that communicates with a USB device using WinUSB
--*/
{
DEVICE_DATA
HRESULT
USB_DEVICE_DESCRIPTOR
BOOL
BOOL
ULONG

deviceData;
hr;
deviceDesc;
bResult;
noDevice;
lengthReceived;

UNREFERENCED_PARAMETER(Argc);
UNREFERENCED_PARAMETER(Argv);
//
// Find a device connected to the system that has WinUSB installed using our
// INF
//
hr = OpenDevice(&deviceData, &noDevice);
if (FAILED(hr)) {
if (noDevice) {
printf(_T("Device not connected or driver not installed\n"));
} else {
printf(_T("Failed looking for device, HRESULT 0x%x\n"), hr);
}
return 0;
}
//
// Get device descriptor
//
bResult = WinUsb_GetDescriptor(deviceData.WinusbHandle,
USB_DEVICE_DESCRIPTOR_TYPE,
0,
0,
(PBYTE) &deviceDesc,
sizeof(deviceDesc),
&lengthReceived);
if (FALSE == bResult || lengthReceived != sizeof(deviceDesc)) {
printf(_T("Error among LastError %d or lengthReceived %d\n"),
FALSE == bResult ? GetLastError() : 0,
lengthReceived);
CloseDevice(&deviceData);
return 0;

}
//
// Print a few parts of the device descriptor
//
printf(_T("Device found: VID_%04X&PID_%04X; bcdUsb %04X\n"),
deviceDesc.idVendor,
deviceDesc.idProduct,
deviceDesc.bcdUSB);
_getch();
CloseDevice(&deviceData);
return 0;
}

You might also like