#include "examples.h"
static BOOL KUSB_API ShowDevicesCB(KLST_HANDLE DeviceList,
KLST_DEVINFO_HANDLE deviceInfo,
PVOID MyContext)
{
printf("%04X:%04X (%s): %s - %s\n",
deviceInfo->Common.Vid,
deviceInfo->Common.Pid,
deviceInfo->Common.InstanceID,
deviceInfo->DeviceDesc,
deviceInfo->Mfg);
return TRUE;
}
DWORD __cdecl main(int argc, char* argv[])
{
KLST_HANDLE deviceList = NULL;
KLST_DEVINFO_HANDLE deviceInfo = NULL;
DWORD errorCode = ERROR_SUCCESS;
ULONG count = 0;
if (!LstK_Init(&deviceList, 0))
{
errorCode = GetLastError();
printf("An error occured getting the device list. errorCode=%08Xh\n", errorCode);
return errorCode;
}
LstK_Count(deviceList, &count);
if (!count)
{
printf("No devices connected.\n");
LstK_Free(deviceList);
return ERROR_DEVICE_NOT_CONNECTED;
}
if (LstK_FindByVidPid(deviceList, EXAMPLE_VID, EXAMPLE_PID, &deviceInfo))
printf("LstK_FindByVidPid: Example device connected!\n");
else
printf("Example device not found.\n");
if (deviceInfo)
{
BOOL success = LibK_SetContext(deviceInfo, KLIB_HANDLE_TYPE_LSTINFOK, 1);
if (success)
{
UINT_PTR myValue = LibK_GetContext(deviceInfo, KLIB_HANDLE_TYPE_LSTINFOK);
printf("MyContextValue = %u\n", myValue);
}
}
LstK_MoveReset(deviceList);
errorCode = ERROR_NO_MATCH;
while(LstK_MoveNext(deviceList, &deviceInfo))
{
if (deviceInfo->Common.Vid == EXAMPLE_VID &&
deviceInfo->Common.Pid == EXAMPLE_PID)
{
errorCode = ERROR_SUCCESS;
break;
}
}
if (deviceInfo)
printf("LstK_MoveNext: Example device connected!\n");
else
printf("Example device not found.\n");
LstK_Enumerate(deviceList, ShowDevicesCB, NULL);
LstK_Free(deviceList);
return errorCode;
}