Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
// Load the NTDLL entry point we need
if( !(NtFsControlFile = (void *) GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" )) ) {
_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
if( !(RtlNtStatusToDosError = (void *) GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"RtlNtStatusToDosError" )) ) {
_tprintf(TEXT("\nCould not find RtlNtStatusToDosError entry point in NTDLL.DLL\n"));
exit(1);
I have these errors at
if(!NtFsControlFile = and if( !(RtlNtStatusToDosError =
,
error C2440: '=' : cannot convert from 'void *' to 'NTSTATUS (__stdcall *)(HANDLE,HANDLE,PIO_APC_ROUTINE,PVOID,PIO_STATUS_BLOCK,ULONG,PVOID,ULONG,PVOID,ULONG)'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
error C2440: '=' : cannot convert from 'void *' to 'ULONG (__stdcall *)(NTSTATUS)'
Conversion from 'void*' to pointer to non-'void' requires an explicit cast
The original page2 was C language file. I need to cast that and how to do it or how can I resolve the problem.
Thanks a lot.
SOLUTION THAT SEEMS TO WORK(NO AUTOMATICALLY CAST LIKE C LANGUAGE):
// a typedef to make casting easier
typedef NTSTATUS (__stdcall *NtFsControlFilePtr)(
HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG FsControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength);
// the actual pointer to function
NtFsControlFilePtr NtFsControlFile;
// and the GetProcAddress call
if( !(NtFsControlFile = reinterpret_cast<NtFsControlFilePtr>( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" ))) ) {
_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
THIS SOLUTION WORKS BUT YOU GET:
C4191: 'reinterpret_cast' : unsafe conversion
with /WALL
to avoid warning:
if( !(NtFsControlFile = reinterpret_cast<NtFsControlFilePtr>( reinterpret_cast< void* >( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" ))))) {
_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
if( !(RtlNtStatusToDosError = reinterpret_cast<RtlNtStatusToDosErrorPtr>( reinterpret_cast< void* >( GetProcAddress( GetModuleHandle(TEXT("ntdll.dll")),
"NtFsControlFile" ))))) {
_tprintf(TEXT("\nCould not find NtFsControlFile entry point in NTDLL.DLL\n"));
exit(1);
declare the variable:
typedef NTSTATUS (__stdcall *NT_FS_CONTROL_FILE)(IN HANDLE FileHandle,
IN HANDLE Event, IN PIO_APC_ROUTINE ApcRoutine,
IN PVOID ApcContext, OUT PIO_STATUS_BLOCKIoStatusBlock,
IN ULONG FsControlCode, IN PVOID InputBuffer,
IN ULONG InputBufferLength, OUT PVOID OutputBuffer,
IN ULONG OutputBufferLength);
NT_FS_CONTROL_FILE nt_fs_control_file;
Then you need
nt_fs_control_file = GetProcAddress(
nt_fs_control_file = (NT_FS_CONTROL_FILE)GetProcAddress
To call your function:
NTSTATUS status = nt_fs_control_file(....);
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.