I am experimenting with a Windows driver and working with Microsofts driver code examples (Minispy to be exact). Unfortunately, i am pretty new to C++ and especially driver development.
While translating the user-mode application from C to C++ (most parts work very well by now), i encountered an interesting cast:
CHAR buffer[1024];
PINSTANCE_FULL_INFORMATION data = (PINSTANCE_FULL_INFORMATION)buffer;
hResult = FilterVolumeInstanceFindFirst(VolumeName,
InstanceFullInformation,
data,
sizeof(buffer) - sizeof(WCHAR),
&bytesReturned,
&volumeIterator);
PWCHAR filtername = PVOID(PUCHAR(data) + data->FilterNameBufferOffset);
filtername[data->FilterNameLength / sizeof(WCHAR)] = L'\0';
if (_wcsicmp(filtername, MINISPY_NAME) == 0) { ...
This part of the code delivers an compiler error C2440: Cannot convert from PVOID to PWCHAR:
filtername = PVOID(PUCHAR(data) + data->FilterNameBufferOffset);
The code worked perfectly fine in C, but C++ won't cast that void pointer "array" to PWCHAR.
I tried for hours now, i could not get it to work. Any ideas?
Many thanks!
For reference:
The PINSTANCE_FULL_INFORMATION struct:
https://msdn.microsoft.com/de-de/library/ff548185(v=vs.85).aspx
The compiler error C2440: