我的USB设备已获得了路径,PATH=“\\?\usb#vid_0471&pid_0888#5&50adea6&0&1#{59f52106-1d99-48c7-ae7e-cd89b6b1ce96}”
strcat (PATH,"\\123.txt");//我的设备里面只放了123.txt这个文件
然后用
h = CreateFile(PATH,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_WRITE | FILE_SHARE_READ,
NULL,
OPEN_EXISTING,//文件必须已经存在
0,//FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL);
h也能够返回成功,可是读不出来数据,另外我把123.txt换成别的不存在的文件也能够返回成功(这里最奇怪)?有大侠知道为什么的吗?
我的读函数是这样的:
OVERLAPPED ovInternal;
char buf[100];
DWORD dwRead=0;
memset(&ovInternal,0,sizeof(OVERLAPPED));
ovInternal.hEvent=CreateEvent(NULL,TRUE,FALSE,NULL);
if(ovInternal.hEvent==NULL)
{
printf("CreateEvent fail\n");
}
LPOVERLAPPED lpOverlapped;
lpOverlapped=&ovInternal;
if( ReadFile(
hDlg,
buf,//ioItem->OutBuffer,
100,
&dwRead,
lpOverlapped))
{
printf("---------------读文件成功dwRead=%d\n",dwRead);
}
else
{
printf("---------------读文件失败\n");
}
int i;
for(i=0;i<100;i++)
printf("--------------------------------------读到的数据:%d\n",buf[i]);//*ioItem->OutBuffer);
------解决方案--------------------
确定是只有一个123文件吗?搜索一下