Answered by:
DeviceIoControl success on Windows 7 but failed on Windows 8

Question
-
Dear all,
I try to migrate my Win7 program to Win8 but encounter DeviceIoControl problem.
I install ndisprot driver first and can use CreateFile to get the driver handle.
*hDev = CreateFile(_T("\\\\.\\\\ndisprot"), GENERIC_WRITE | GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 0);
After obtaining the driver handle, I use DeviceIoControl to open the driver.
bResult = DeviceIoControl(*hDev, IOCTL_NDISPROT_OPEN_DEVICE, szAdapterName, (DWORD)_tcslen(szAdapterName)*sizeof(WCHAR), NULL, 0, &dwBytesReturned, 0);
The code above can run on Win XP, Vista, 7 without any problem instead of Windows 8.
I always obtain error code: 2 (The system cannot find the file specified.) during calling the DeviceIoControl, but don't why.
I real suffer about this problem.
Is there any different between Win8 and other Win OS?
And, how can I use the DeviceIoControl on Win8?
Thank you.
- Edited by Zuzu Wu Tuesday, September 18, 2012 1:34 PM
Tuesday, September 18, 2012 1:33 PM
Answers
-
Assuming your driver is based of the NDISPROT sample, then the problem is that the "szAdapterName" is not a correct adapter name. Look up the available adapters using IOCTL_NDISPROT_QUERY_BINDING to see which devices the NDISPROT protocol is bound to.
- Marked as answer by Doron Holan [MSFT] Wednesday, September 19, 2012 6:32 PM
Tuesday, September 18, 2012 7:40 PM
All replies
-
Assuming your driver is based of the NDISPROT sample, then the problem is that the "szAdapterName" is not a correct adapter name. Look up the available adapters using IOCTL_NDISPROT_QUERY_BINDING to see which devices the NDISPROT protocol is bound to.
- Marked as answer by Doron Holan [MSFT] Wednesday, September 19, 2012 6:32 PM
Tuesday, September 18, 2012 7:40 PM -
Hi Jeffrey,
Thanks for your responds. Unfortunately, I still cannot use this IO control code on Windows 8.
However, I can query ndis on Windows 7 by using DeviceIoControl() without any problem.
The following code snip works well on Win7.
BOOL bResult; char Buf[1024]; DWORD BufLength = sizeof(Buf); DWORD BytesWritten; PNDISPROT_QUERY_BINDING pQueryBinding; WCHAR *strDeviceName[256][2]; pQueryBinding = (PNDISPROT_QUERY_BINDING)Buf; int i = 0; for (pQueryBinding->BindingIndex = i; /* NOTHING */; pQueryBinding->BindingIndex = ++i) { bResult = DeviceIoControl(hDev, IOCTL_NDISPROT_QUERY_BINDING, pQueryBinding, sizeof(NDISPROT_QUERY_BINDING), Buf, BufLength, &BytesWritten, NULL); if (bResult == 0) { dwError = GetLastError(); printf("(%d) !!ERROR %d: \n", iIndex, dwError); } else { strDeviceName[pQueryBinding->BindingIndex][0] = (WCHAR *)((PUCHAR)pQueryBinding + pQueryBinding->DeviceNameOffset); strDeviceName[pQueryBinding->BindingIndex][1] = (WCHAR *)((PUCHAR)pQueryBinding + pQueryBinding->DeviceDescrOffset); //break; } }
I am not sure DeviceIoControl API can work on Windows 8 or not.
Or, is there any API can call device io control call to device?
Thank you.
Wednesday, September 19, 2012 7:48 AM -
DeviceIoControl() function is working differently in Windows 7 and Windows 8
I am trying to get the Hard Disk Serial using DeviceIoControl function. And calling it with same parameters it gives different value in output buffer in case of win7 and win8.
I am caliing it as
if ( DeviceIoControl (hPhysicalDriveIOCTL, IOCTL_STORAGE_QUERY_PROPERTY, & query, sizeof (query), & buffer, sizeof (buffer), & cbBytesReturned, NULL) )
where hPhysicalDriveIOCTL = CreateFile (TEXT(deviceName), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
Friday, January 24, 2014 7:19 AM