我有这个代码:
// page1.h
NTSTATUS (__stdcall *NtFsControlFile)(
HANDLE FileHandle,
HANDLE Event,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG FsControlCode,
PVOID InputBuffer,
ULONG InputBufferLength,
PVOID OutputBuffer,
ULONG OutputBufferLength
);
ULONG (__stdcall *RtlNtStatusToDosError) (
IN NTSTATUS Status
);
然后在page2.cpp:
page2.cpp
VOID LocateNativeEntryPoints()
{
//
// If we're on Win9x, just return
//
if( GetVersion() >= 0x80000000) return;
//
// 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);
}
}
我有这些错误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
原来的page2是C语言文件。我需要转换它以及如何做或如何解决问题。
非常感谢。
似乎可行的解决方案(没有像 C 语言那样自动转换):
// 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);
}
此解决方案有效,但您得到:
C4191:'reinterpret_cast':不安全的转换
与 /WALL
避免警告:
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);
}