for循环到第4次时CreateFile就失败了,GetLastError值为2,这是什么原因啊,怎么解决。
BOOL HY_Get_USBDevice(void)
{
CHAR HCName[32];
int HCNum;
HANDLE hHCDev;
for (HCNum = 0; HCNum < 10; HCNum++)
{
sprintf(HCName, "\\\\.\\HCD%d", HCNum);
hHCDev = CreateFile(HCName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
if (hHCDev == INVALID_HANDLE_VALUE)
{
int rst = GetLastError();
break;
}
}
......
}
------解决方案--------------------
2的意思就是 ERROR_FILE_NOT_FOUND The system cannot find the file specified.