Abdul Qader wrote:
I created an IOCTL in my user app as well as in the driver with the
following code:
#define IOCTL_KEYBOARD_TRANSFER_DATA CTL_CODE(FILE_DEVICE_KEYBOARD,
0x800 , METHOD_BUFFERED , FILE_READ_DATA )
Now from my user app : I call the following code:
char output[100];
DWORD dwSize = 0;
memset(output, 0, sizeof(output));
HANDLE hFile = CreateFile(L"\.\kbDevice", GENERIC_ALL,
FILE_SHARE_WRITE|FILE_SHARE_READ, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); //using symbolic link as
CreateFile fails with DeviceInterfaces.
dwError = GetLastError();
if(hFile == INVALID_HANDLE_VALUE)
{
dwError = GetLastError();
}
DeviceIoControl(hFile, IOCTL_KEYBOARD_TRANSFER_DATA, NULL,
0,(void*)output, sizeof(output), &dwSize, NULL);
dwError = GetLastError());
I get dwError = 87 which is Invalid_Parameter.
I am not even getting call into my drivers Dipatch routine…
What could be the problem…
The likely problem is that your CreateFile is failing, so you get an
invalid handle. Even though you call GetLastError, you don’t ever check
the value, nor do you stop your processing. You just continue on
blindly. I’m not sure what you think those GetLastError calls are doing.
Your file name is incorrect. You need another backslash pair:
L"\\.\kbDevice".
Is this a HID driver? HID drivers are opened exclusively by the HID
stack. You can’t open your own handle.
Although this is really a style point, it always makes me a little
uneasy to see:
char buffer[100];
…( … buffer, sizeof(buffer) … );
because sooner or later, you’re going to want to make buffer a heap
variable, so you’ll change it to:
char * buffer = malloc(100);
and now you have a bug, because sizeof returns the wrong thing. It is
much better, in my opinion, to say:
#define BUFFER_SIZE 100
char buffer[BUFFER_SIZE];
…( … buffer, BUFFER_SIZE, … );
Or, even better:
std::vector buffer( 100 );
…( … &buffer[0], buffer.size(), … );
–
Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.