本文介绍了为什么DeviceIoControl会因“功能不正确”而失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试与USB驱动程序进行通信。我可以获取一个句柄,但是一旦我使用 DeviceIoControl 失败, GetLastError()表示错误是不正确的功能。我对如何调试此方法感到困惑。我正在使用XP 32位计算机。

I am trying to communicate with my USB driver. I am able to get a handle, but once I use DeviceIoControl it fails, GetLastError() says error is an incorrect function. I am stumped on how to debug this. I am using XP 32bit machine.

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指出的)是设备驱动程序的较新版本没有该特定的控制代码。您需要从供应商处获取更新的文档和/或头文件。

The most likely cause (as Xearinox pointed out) is that the newer version of the device driver does not have that particular control code. You need to obtain updated documentation and/or header files from the vendor.

此外,您正在打开一个异步句柄,然后尝试将其用于同步I / O。从DeviceIoControl的文档中:

Also, you are opening an asynchronous handle and then trying to use it for synchronous I/O. From the documentation for DeviceIoControl:

这篇关于为什么DeviceIoControl会因“功能不正确”而失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 15:00