Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

CTL_CODE (kernel32)
 
.
Summary
Define a new IO Control Code.

C# Signature:

private static UInt32 CTL_CODE(uint DeviceType, uint Function, IOCTL_METHOD Method, IOCTL_ACCESS Access)
{
    return ((DeviceType << 16) | (((uint)Access) << 14) | (Function << 2) | ((uint)Method));
}

VB Signature:

TODO: please add

User-Defined Types:

private const uint FILE_DEVICE_UNKNOWN = 0x00000022;

private enum IOCTL_METHOD : uint
{
    METHOD_BUFFERED = 0,
    METHOD_IN_DIRECT = 1,
    METHOD_OUT_DIRECT = 2,
    METHOD_NEITHER = 3
}

private enum IOCTL_ACCESS : uint
{
    FILE_ANY_ACCESS = 0,
    FILE_READ_ACCESS = 1,
    FILE_WRITE_ACCESS = 2
}

Alternative Managed API:

Notes:

for custom use DeviceType FILE_DEVICE_UNKNOWN or 0x8000 and above

for custom use Function 0x800 and above

see also https://www.pinvoke.net/default.aspx/kernel32/DeviceIoControl.html

Tips & Tricks:

https://www.codeproject.com/Articles/9575/Driver-Development-Part-2-Introduction-to-Implemen

https://www.pinvoke.net/default.aspx/coredll.kerneliocontrol

Sample Code:

      UInt32 IOCTL_CUSTOM_00 = CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, IOCTL_METHOD.METHOD_BUFFERED, IOCTL_ACCESS.FILE_ANY_ACCESS);

Documentation:

https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/defining-i-o-control-codes

https://docs.microsoft.com/en-us/windows-hardware/drivers/kernel/specifying-device-types

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions