Note that there are some explanatory texts on larger screens.

plurals
  1. PODeviceIOControl() gives Error 50
    primarykey
    data
    text
    <p>I'm very new to communication with Windows Device Drivers.</p> <p>A) I need to communicate with a third-party driver. I see that <code>CreateFile()</code> accept both the device name (such as <code>\\\\.\\DeviceName</code>) and also I can call the full file name (such as <code>\\\\.\\C:\\MyPath\\DriverName.sys</code>). What is the best option? Why? Both works on the same way?</p> <p>B) I see that many device drivers has two names, for example:</p> <pre><code>SymbolicLink "\GLOBAL??\VirtualSerial" Destination "\Device\VrSerialrs232" </code></pre> <p>If I try open for example open <code>VrSerialrs232</code> with <code>CreateFile()</code> it fails. So, why is used the <code>VrSerialrs232</code> if I always have to call the <code>SymbolicLink(VirtualSerial)</code>?</p> <p>C) I installed a <code>DeviceIOControl</code> monitor to check why my code is failing with <code>Error 50</code> (The request is not supported) and I can't figure why. </p> <p>The output of the <code>DeviceIOControl</code> monitor is <a href="http://img254.imageshack.us/img254/5439/picggi.png" rel="nofollow">here</a></p> <p>The ones from <code>test.exe</code> are my code, the other (protected) is the original application calling the same device.</p> <p>My code is like this:</p> <pre><code>#include "stdafx.h" #include &lt;windows.h&gt; #include &lt;stdio.h&gt; #include &lt;strsafe.h&gt; void ErrorExit(LPTSTR lpszFunction){ // Retrieve the system error message for the last-error code LPVOID lpMsgBuf; LPVOID lpDisplayBuf; DWORD dw = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &amp;lpMsgBuf, 0, NULL ); // Display the error message and exit the process lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); StringCchPrintf((LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(TCHAR), TEXT("%s failed with error %d: %s"), lpszFunction, dw, lpMsgBuf); MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); LocalFree(lpMsgBuf); LocalFree(lpDisplayBuf); ExitProcess(dw); } BOOL OpenDevice(PWSTR DriverName, HANDLE *lphDevice){ WCHAR DeviceName[MAX_PATH]; HANDLE hDevice; if ((GetVersion() &amp; 0xFF) &gt;= 5) { wcscpy(DeviceName, L"\\\\.\\Global\\"); } else { wcscpy(DeviceName, L"\\\\.\\"); } wcscat(DeviceName, DriverName); printf("Opening.. %S\n", DeviceName); hDevice = CreateFileW(DeviceName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hDevice == INVALID_HANDLE_VALUE) { printf("CreateFile() ERROR %d\n", GetLastError()); return FALSE; } *lphDevice = hDevice; return TRUE; } int _tmain(int argc, _TCHAR* argv[]){ HANDLE hDevice = NULL; DWORD cb = 0; int ret = 0; char tcode[] = "\x8a\xb3\x39\x9d"; /* Copied from original request seen on Monitor) */ if(!OpenDevice(L"MyDeviceName",&amp;hDevice)) { printf("Error: Error opening device\n"); return(0); } else { printf("Device succesfully opened!\n"); } char *Buff = (char *)VirtualAlloc(NULL, 0x330, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE); if (Buff){ ret = DeviceIoControl(hDevice, 0xa028442f, tcode, 0x04, 0, NULL, &amp;cb, (LPOVERLAPPED)NULL); if (ret == 0) { printf("Error: Bytes returned %#x\n",cb); ErrorExit(TEXT("DeviceIoControl: ")); } } CloseHandle(hDevice); return(0); } </code></pre> <p>I always get this error:</p> <pre><code>C:&gt;Test.exe Opening.. \\.\Global\MyDeviceName Device succesfully opened! Error: Bytes returned 0 DeviceIOControl: Error 50 - The request is not supported </code></pre> <p>Why?</p> <p>I don't know the name of the IOCTL commands, but I know the numbers. There is a way to translate a IOCTL number to a name?</p> <p>This is a valid and real request that I captured with a IOCTL monitor.</p> <pre><code>Log started... 'C:\PathToApplication\OriginalAppName.exe' (PID: 2896) '\Device\VSFilterbpd' (0x86b83c40) [\??\C:\LocalPath\DeviceDriverName.sys] SymbolicLink "\GLOBAL??\VSFFilter" IOCTL Code: 0xa028442f, Method: METHOD_NEITHER InBuff: 0x004883a4, InSize: 0x00000004 -------------------------------------------------------------------- 9c 84 e2 86 | .... OutBuff: 0x004b4f68, OutSize: 0x00001b20 -------------------------------------------------------------------- 03 00 00 00 1c 03 00 00 00 00 00 00 00 00 00 00 | ................ 00 00 00 00 e4 0c 00 00 00 00 00 00 00 00 00 00 | ................ A lot of data. </code></pre> <p>What I'm missing to reproduce / clone / replicate the exact same message to the same driver by from my own application?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload