CTL_CODE (kernel32)
Last changed: -84.110.53.106

.
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