As an exercise I am currently porting some of my code from C/C++ to C#. Since the Framework does not have the low level Win32 support I have to link directly to the dll exports, namely DeviceIoControl, CreateFile, ReadFile, WriteFile.
While all this works like a charm I am running into a snag. I am porting over all the defined values in the Win32 header files. Many of them are defined through macros, especially the DeviceIoControlCodes.
What would be an elegant solution in C# so I don't have to hardcode each value but would be able to make them dependant on a few parameters.
Original macro from the "winioctl.h" file:
#define CTL_CODE( DeviceType, Function, Method, Access ) (((DeviceType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method))
This makes if very simple to define private control codes
How would this look like in C# without hardcoding the value?