1
我想用我的USB驅動程序進行通信。我能夠獲得一個句柄,但一旦我用DeviceIoControl
失敗,GetLastError()
說,錯誤是不正確的函數。我難以理解如何進行調試。我正在使用XP 32位機器。爲什麼DeviceIoControl的失敗,「不正確的函數」
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);
,驅動程序代碼是在哪裏呢? – Xearinox 2012-08-12 13:45:14
@Xearinox如果我下正常站在你,我的控制代碼'#定義USB_TEST_IOCTL_VERSION_NUMBER CTL_CODE(FILE_DEVICE_UNKNOWN,0x807,METHOD_BUFFERED,FILE_ANY_ACCESS)''那裏CTL_CODE' is'#定義CTL_CODE(設備類型,函數,方法,訪問)(\ ( (設備類型)<< 16)|((訪問)<< 14)|((功能)<< 2)|(方法)\ )'這是傳遞給設備驅動程序,並最終於USB。我的驅動程序位於WINDOWS \ system32 \ DRIVERS \ myDriver.sys' – IPA8654 2012-08-12 21:43:18
OK。但是,在驅動程序中響應這個IOCTL的代碼在哪裏? – Xearinox 2012-08-12 21:58:04