how to read the data in visual c++ when I compile the read data part ,the return value is 0.I can not find the reason, somebody can help me? thanks.
my read data part as follow:
USBLUMS_API int LumsReadData(char* data)
{
char buf[64];
memset(buf, 0, sizeof(buf));
HANDLE dHandle;
dHandle = CreateFile("\\\\.\\ezusb-0",
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (dHandle == INVALID_HANDLE_VALUE)
{
return -4;
// AfxMessageBox("Fail to open driver.");
// KillTimer(Timer);
}
else // When Driver is open successfully.
{
BOOLEAN pass;
ULONG nBytes = 0;
BULK_TRANSFER_CONTROL btc;
btc.pipeNum = 0; //Pipe: 0 Type: BLK Endpoint: 6 IN MaxPktSize: 0x40
pass = DeviceIoControl (dHandle,
IOCTL_EZUSB_BULK_READ,
&btc,
sizeof(BULK_TRANSFER_CONTROL),
buf,
sizeof(buf),
&nBytes,
NULL);
if(pass)//if writing of data success
{
if (nBytes == sizeof(buf))
return 6;
else
return -4; // Write is incomplete
}
UpdateData(FALSE);
}
else
{
return -5;
// AfxMessageBox("Unable to read from device.");
// KillTimer(Timer);
}
CloseHandle(dHandle);
}
//return 0;
} |