I have a C++ program which is compiled for x86 (32 bit). It is calling a kernel mode driver. The driver is compiled for the word size of the OS both are running on. The target operating systems may be 32 or 64 bit (in my case windows).
My problem is to determine the size of a pointer returned by the driver, as it is needed by an OS call.
The following call of the user mode program worked if the system had a word size of 32 bit:
HANDLE device = OpenDevice();
HANDLE packageReceivedEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
bool result = DeviceIoControl(
device,
IOCTL_CODE,
&packageReceivedEvent, //for signaling
sizeof(HANDLE), //TODO does not work for 64 bit
nullptr,
0,
&recvBytes,
nullptr);
The definitions come from standard winbase.h and winnt.h.
I cannot use any compile time solutions like sizeof(int)
, as they would only regard the user mode program, not the driver compilation it is depending on.
Probably it would suffice to set the DeviceIoControl
's nInBufferSize
simply to the highest expected word size, but is there a nicer solution?