0
我有這樣的代碼:NtFsControlFile功能錯誤
// 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
原來第2頁是C語言ge文件。我需要演示該如何做,或者我該如何解決這個問題。
非常感謝。
解似乎工作(NO自動轉換LIKE 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);
}
是否真正含有'page2.cpp' C++代碼? – alk
是的,我嘗試建立一個班級 –