Mattias,
I doubt that the error code is coming from the user mode process,
DeviceIoControl() won’t do any parameter checking in user mode and
once the transition is made to kernel mode it will just plug the
passed in values to an IRP and send it down to the open device.
If you look in the driver where the IRP is handled,
SioctlDeviceControl() you will see the following:
if (!inBufLength || !outBufLength)
{
ntStatus = STATUS_INVALID_PARAMETER;
goto End;
}
My guess is that this is where the status code is coming from. Try
adding some debug in both user mode and kernel mode to check
precisely what values for these variables are being sent from user
mode and presented to the driver.
The sample driver is quite good at showing how the different ioctl
types need to be handled, but like quite a few of the user mode code
samples, testapp.c is not of the greatest quality. If you’ve added
some of your own code to the test sample, trace everything you’ve
done to find out what you might have affected.
Oh, and one thing more. If you’re just using the sample “as is”, why
don’t you try compiling in a WDK command line with build.exe ? It’s
how the sample is given in the WDK and removes any concerns about
getting the VS options correct.
Mark.
At 08:43 14/05/2008, you wrote:
Hello!
I try to send message from User mode to Kernel mode by using IOCTL.
My problem is in my user process when I use DeviceIoControl it
always returning 87, invalid parameter. I have copied the IOCTL
example from the wddk and compiling it in Visual Studio.
Could any body tell me what parameter is wrong?
char OutputBuffer[100];
char InputBuffer[100];
hDevice = CreateFile( (LPCTSTR)“\\.\IoctlTest”,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
DeviceIoControl ( hDevice,
(DWORD) IOCTL_SIOCTL_METHOD_NEITHER,
&InputBuffer,
strlen ( InputBuffer )+1,
&OutputBuffer,
sizeof( OutputBuffer),
&bytesReturned,
NULL);
What can it be?
Best regards
Mattias Bergkvist