Click here to Skip to main content
14,699,224 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi there!

I'm trying to make my own IOCTL driver command for calling it from an user-mode application DLL. For now I just wanted to make sure the DLL successfully calls that command on the driver code. So I defined my command (in the DLL and in the driver's code) like this:

define BUSENUM_IOCTL(index) \
CTL_CODE (FILE_DEVICE_BUS_EXTENDER, _index_, METHOD_BUFFERED, FILE_ANY_ACCESS)
...

define IOCTL_DEBUG_LOG_INFO BUSENUM_IOCTL (0x4)


in the driver code, in my corresponding IRP_MJ_DEVICE_CONTROL function, I have something like this:

switch ( command )
    {
  case IOCTL_DEBUG_LOG_INFO:
   KdPrint(("IOCTL_DEBUG_LOG_INFO:\n"));
   if(devExt->Type==0)
   {
    status = STATUS_SUCCESS;
   }
   else
   {
    status=STATUS_INVALID_DEVICE_REQUEST;
    KdPrint(("Wrong device on IOCTL_DEBUG_LOG_INFO command"));
   }
   break;
...
}

and in the dll code I'm calling the driver's command like this:

if (DeviceIoControl(h, IOCTL_DEBUG_LOG_INFO,
      debugLogInfoData, sizeof(DEBUG_LOG_INFO),
      debugLogInfoData, sizeof(DEBUG_LOG_INFO),
      junk, NULL))
 {
  CloseHandle(h);

  ...

  return VDD_NO_ERROR;
 }

 PrintLastError(prefix);

 return VDD_UNKNOWN_ERROR;
}

(where h is the handle initialized when I opened the stub driver (devExt->Type==0) )

but it always goes to the 'VDD_UNKNOWN_ERROR'; with the error code 1: Incorrect function

What am I doing wrong? ...

Help please!
Posted
Updated 22-Apr-16 3:59am
v2

1 solution

In your dll maybe you should try

if (DeviceIoControl(h, IOCTL_DEBUG_LOG_INFO, debugLogInfoData, sizeof(DEBUG_LOG_INFO), debugLogInfoData, sizeof(DEBUG_LOG_INFO), junk, NULL)) == STATUS_SUCCESS


I don't know what the value of STATUS_SUCCES is but that's what the if is testing on right? I guess the return value is an error code or zero when everything went okay, but with booleans it's the other way around. zero means false and not zero is true. Could this be the problem?

Good luck!
   
v2
Comments
Cosmin D Popescu 11-May-10 15:15pm
   
Thanks a lot!
... but unfortunately in MSDN it says that:


Return Value

If the operation completes successfully, the return value is nonzero.

If the operation fails or is pending, the return value is zero. To get extended error information, call GetLastError.
E.F. Nijboer 12-May-10 14:18pm
   
Your right. Maybe you seen this, but hopefully you didn't (so it could possibly help you).

http://msdn.microsoft.com/en-us/library/aa363147(VS.85).aspx

again... good luck!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900