我正在尝试与我的 USB 驱动程序进行通信。我能够得到一个句柄,但是一旦我使用DeviceIoControl
它失败,GetLastError()
说错误是一个不正确的功能。我对如何调试这个感到困惑。我正在使用 XP 32 位机器。
Handle = CREATEFILE( DevicePath1,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (INVALID_HANDLE_VALUE == Handle)
{
printf("INVALIDHANDLE USB\n");
return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);
}
else
{
// Call device IO Control interface (USB_TEST_IOCTL_VERSION_NUMBER) in driver
if ( !DeviceIoControl(Handle,
USB_TEST_IOCTL_VERSION_NUMBER,
NULL,
0,
version,
sizeof(version),
&lenght,
NULL)
)
{
//Display the last error killing my program
void* lpBuffer;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpBuffer,
0,
NULL );
printf(" Version: %x\n", version);
printf("USB_TEST_IOCTL_VERSION_NUMBER, %x\n", USB_TEST_IOCTL_VERSION_NUMBER);
printf(" &lenght: %x\n", &lenght);
MessageBox( NULL, (LPCTSTR)lpBuffer, TEXT("LastRrror"), MB_OK );
LocalFree( lpBuffer );
printf("USB HIO Control interface FAIL\n");
return PHNFCSTVAL(CID_NFC_DAL, NFCSTATUS_INVALID_DEVICE);