libusbK 
3.0
Library Documentation
© 2011-2021 Travis Lee Robinson. All rights reserved.
load-driver-api.c

Loads a dynamic driver api for use with all drivers and opens the device.

load-driver-api example:
  1. Finds a device by vid/pid (use vid=hhhh, pid=hhhhh and the command line).
  2. Loads a dynamic driver API set specific to the devices driver.
  3. Initializes a new UsbK (usb device) handle.
  4. Frees the UsbK (usb device) handle.
  5. Frees the LstK (device list) handle created in step #1.
Console Output
Looking for device vid/pid 04D8/FA2E..
Using 04D8:FA2E (LUSBW1): Benchmark Device - Microchip Technology, Inc.
libusbK driver api loaded!
Device opened successfully!
#include "examples.h"
// Globals
DWORD __cdecl main(int argc, char* argv[])
{
KLST_HANDLE deviceList = NULL;
KLST_DEVINFO_HANDLE deviceInfo = NULL;
KUSB_HANDLE handle = NULL;
DWORD errorCode = ERROR_SUCCESS;
// Find the test device. Uses "vid/pid=hhhh" arguments supplied
// on the command line. (default is: vid=04D8 pid=FA2E)
if (!Examples_GetTestDevice(&deviceList, &deviceInfo, argc, argv))
return GetLastError();
// load a dynamic driver api for this device. The dynamic driver api
// is more versatile because it adds support for winusb.sys devices.
if (!LibK_LoadDriverAPI(&Usb, deviceInfo->DriverID))
{
errorCode = GetLastError();
printf("LibK_LoadDriverAPI failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
// Display some information on the driver api type.
switch(deviceInfo->DriverID)
{
printf("libusbK driver api loaded!\n");
break;
printf("libusb0 driver api loaded!\n");
break;
printf("WinUSB driver api loaded!\n");
break;
printf("libusb0/filter driver api loaded!\n");
break;
}
/*
From this point forth, do not use the exported "UsbK_" functions. Instead,
use the functions in the driver api initialized above.
*/
// Initialize the device with the "dynamic" Open function
if (!Usb.Init(&handle, deviceInfo))
{
errorCode = GetLastError();
printf("Usb.Init failed. ErrorCode: %08Xh\n", errorCode);
goto Done;
}
printf("Device opened successfully!\n");
Done:
// Close the device handle
// if handle is invalid (NULL), has no effect
UsbK_Free(handle);
// Free the device list
// if deviceList is invalid (NULL), has no effect
LstK_Free(deviceList);
return errorCode;
}