代码 :
hHCDev = CreateFileA(completeDeviceName,
//"F:\\test.txt",
GENERIC_WRITE|GENERIC_READ,
FILE_SHARE_WRITE|FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hHCDev == INVALID_HANDLE_VALUE)
{
CloseHandle(hHCDev);
}
else
{
char bufRead[256] = {0};
DWORD countRead = 0;
BOOL result ;
result = ReadFile(hHCDev, bufRead, 5, &countRead, NULL) ;
if(!result)
{
printf("Reading file error %d\n", GetLastError());
}
char bufWrite[] = {'7', '8', '9', ' '};
DWORD countWritten = 0;
result = WriteFile(hHCDev, bufWrite, 3, &countWritten, NULL) ;
if(!result)
{
printf("Writing file error %d\n", GetLastError());
}
else
{
printf("sucess");
}
CloseHandle(hHCDev);
}
memset(completeDeviceName,0,256) ;
描述:
我们尝试打开使用 createfile() 连接的 USB 设备。使用 Readfile 和 Writefile() 调用,我们尝试与设备通信。但是这些调用返回错误代码 1。可能是什么原因?
您的帮助将不胜感激。
最好的问候苏伦