Hallo Ihr,
nachdem ich nun an meinem USB Problem weitergemacht habe kommt ein
komischer Fehler. Ich habe das Handle auf einen USB Device, aber
ich kann komischer Weise keine DeviceIoControl Funktionen darauf
aufrufen.
Zum Ausprobieren habe ich einen einfachen Fall genommen, einfach mal die
Treiberversion zu erfragen. Jedoch wird bei diesem Aufruf immer mit
Error 1 (ERROR_INVALID_FUNCTION) beendet.
Hier ist mein Code dafür. Nix besonderes.
1. Handle holen (funktioniert)
2. Treiberversion erfragen (funktioniert nicht)
3. Handle wieder abgeben (funktioniert)
1 | DWORD nBytes;
|
2 | DRV_VERSION dVer = {0, 0, 0};
|
3 |
|
4 | HANDLE hUsbDevice = CreateFile( TEXT("\\\\?\\usb#vid_067b&pid_2305#5&10b270c0&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"), // name of the file or device to be created or opened.
|
5 | GENERIC_READ | GENERIC_WRITE, // access mode of device
|
6 | 0, // dont share device
|
7 | NULL, // handle can not be inherited by any child process
|
8 | OPEN_EXISTING, // opens a file or device, only if it exists
|
9 | 0, // no device attributes and flags
|
10 | NULL); // handle to a template file with the GENERIC_READ access right
|
11 |
|
12 | if(hUsbDevice == INVALID_HANDLE_VALUE)
|
13 | wcout << L"Couldn't get handle" << endl;
|
14 | else
|
15 | wcout << L"Handle: " << hUsbDevice << endl;
|
16 |
|
17 |
|
18 | // DeviceIoControl need administrator privileges to succeed
|
19 | bool success = DeviceIoControl( hUsbDevice,
|
20 | IOCTL_GET_VERSION,
|
21 | NULL,
|
22 | 0,
|
23 | &dVer,
|
24 | sizeof(DRV_VERSION),
|
25 | &nBytes,
|
26 | NULL);
|
27 | if(success)
|
28 | printf("Version: %d.%d\n",dVer.major,dVer.minor);
|
29 | else
|
30 | printf("Error %d in IOCTL_GET_VERSION\n",GetLastError());
|
31 |
|
32 |
|
33 |
|
34 | // close device
|
35 | CloseHandle(hUsbDevice) ;
|
Kann mir jemand einen Tipp geben?
Viele Grüße,
Ai