2012-10-28 225 views
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); 
    } 
+0

是否真正含有'page2.cpp' C++代碼? – alk

+0

是的,我嘗試建立一個班級 –

回答

0

如果您有純C代碼,你可以強制轉換改了一下,我的意思是:

  1. 聲明變量:

    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; 
    

    然後,你需要

    nt_fs_control_file = GetProcAddress(
    

    nt_fs_control_file = (NT_FS_CONTROL_FILE)GetProcAddress 
    
  2. 要調用你的函數:

    NTSTATUS status = nt_fs_control_file(....);