27,372
社区成员
发帖
与我相关
我的任务
分享
HRESULT readfromdevice(_Inout_ PDEVICE_DATA DeviceData)
{
BOOL bResult = NULL;
ULONG cbSize = 200;
UCHAR *szBuffer = (UCHAR*)LocalAlloc(LPTR, sizeof(UCHAR)*cbSize);
ULONG cbRead = 0;
HRESULT error_infomation;
// 若接口不存在
if (DeviceData->WinusbHandle == INVALID_HANDLE_VALUE){
printf("the device is invalid\n");
}
// 读取pipe中的内容
bResult = WinUsb_ReadPipe(DeviceData->WinusbHandle, DeviceData->InPipe, szBuffer, cbSize, &cbRead, 0);
// 若读取失败
if (!bResult){
error_infomation = HRESULT_FROM_WIN32(GetLastError());
printf("read pipe failed %x\n", bResult);
}
if (szBuffer[0] != 0)
printf("lvshiqi\n");
printf("Read from pipe 0x%x: %s\nActual data read: %d.\n", DeviceData->InPipe, szBuffer, cbRead);
// 释放szBuffer
LocalFree(szBuffer);
return 0;
}