2017-07-07 44 views
-1

我面臨Wow64DisableWow64FsRedirection()的問題。當在Windows 10中的Visual Studio中爲64位編譯時,Wow64DisableWow64FsRedirection()函數無法正常工作

當我編譯在Visual Studio 2010在64位平臺上,它不是在窗口10個,這與錯誤1.

返回但是,當我編譯爲32位平臺相反,在窗口10

typedef BOOL(__stdcall *tFSRED)(HMODULE); 

HMODULE hKernel = LoadLibrary(_T("Kernel32.dll")); // Get Kernel module handle 
if (hKernel == NULL) 
{ 
    return 2; 
} 

tFSRED pFunc; 
pFunc = (tFSRED) GetProcAddress(hKernel, "Wow64DisableWow64FsRedirection"); 
ret = pFunc(&oldValue); // Turn the file the file system redirector off 
if (ret == FALSE) 
{ 
    _tprintf(_T("\nFile System Redirection could not be turned off. Reason: %d"), GetLastError()); 
    return 4; 
} 
// ret is always TRUE when compile through 32-bit platform 
// but ret return FALSE when compile through 64-bit platform 

函數工作在Visual Studio中,如果我編譯爲64位平臺,那麼如果我在depends.exe打開生成EXE編譯後,它顯示64在EXE的前面。

選擇32位平臺後,生成的EXE是32位。這個EXE適用於我的情況,但我希望我的EXE是64位的,所以我選擇了64位平臺,並且我得到了一個64位的EXE,但它並不像我上面所解釋的那樣工作。

+0

將代碼包含在問題主體中,以便您可以將代碼格式正確地編碼爲代碼。 – zett42

回答

0

WOW64仿真僅適用於在64位系統上運行的32位可執行文件。 64位EXE 不應該嘗試使用WOW64功能(除IsWow64Process()之外),因爲EXE不會在WOW64內部運行以開始。這就是爲什麼你在64位EXE中得到錯誤代碼1(ERROR_INVALID_FUNCTION)的原因。

所以,要麼:

  • ifdef的代碼跳過64位編譯WOW64功能:

    #ifndef _WIN64 
    typedef BOOL (WINAPI *tFSDisable)(PVOID*); 
    typedef BOOL (WINAPI *tFSRevert(PVOID); 
    
    HMODULE hKernel = GetModuleHandle(_T("Kernel32")); 
    tFSDisable pDisableFunc = (tFSDisable) GetProcAddress(hKernel, "Wow64DisableWow64FsRedirection"); 
    tFSRevert pRevertFunc = (tFSRevert) GetProcAddress(hKernel, "Wow64RevertWow64FsRedirection"); 
    
    PVOID oldValue; 
    
    if ((pDisableFunc) && (pRevertFunc)) 
    { 
        if (!pDisableFunc(&oldValue)) // Turn off the file system redirector 
        { 
         _tprintf(_T("\nFile System Redirection could not be turned off. Reason: %d"), GetLastError()); 
         return 4; 
        } 
    } 
    #endif 
    
    // do file system operations as needed... 
    
    #ifndef _WIN64 
    if ((pDisableFunc) && (pRevertFunc)) 
    { 
        if (!pRevertFunc(oldValue)) // Restore the file system redirector 
        { 
         _tprintf(_T("\nFile System Redirection could not be restored. Reason: %d"), GetLastError()); 
         return 5; 
        } 
    } 
    #endif 
    
  • 省略IFDEF並調用WOW64功能只有IsWow64Process()報告目前的過程實際上是在WOW64裏面運行的:

    typedef BOOL (WINAPI tW64P)(HANDLE, PBOOL); 
    typedef BOOL (WINAPI *tFSDisable)(PVOID*); 
    typedef BOOL (WINAPI *tFSRevert(PVOID); 
    
    HMODULE hKernel = GetModuleHandle(_T("Kernel32")); 
    
    tW64P pIsWow64Func = (tW64P) GetProcAddress(hKernel, "IsWow64Process"); 
    tFSDisable pDisableFunc = NULL; 
    tFSRevert pRevertFunc = NULL; 
    
    BOOL bIsWow64 = FALSE; 
    if (pIsWow64Func) 
    { 
        pIsWow64Func(GetCurrentProcess(), &bIsWow64); 
        if (bIsWow64) 
        { 
         pDisableFunc = (tFSDisable) GetProcAddress(hKernel, "Wow64DisableWow64FsRedirection"); 
         pRevertFunc = (tFSRevert) GetProcAddress(hKernel, "Wow64RevertWow64FsRedirection"); 
        } 
    } 
    
    PVOID oldValue; 
    
    if ((pDisableFunc) && (pRevertFunc)) 
    { 
        if (!pDisableFunc(&oldValue)) // Turn off the file system redirector 
        { 
         _tprintf(_T("\nFile System Redirection could not be turned off. Reason: %d"), GetLastError()); 
         return 4; 
        } 
    } 
    
    // do file system operations as needed... 
    
    if ((pDisableFunc) && (pRevertFunc)) 
    { 
        if (!pRevertFunc(oldValue)) // Restore the file system redirector 
        { 
         _tprintf(_T("\nFile System Redirection could not be restored. Reason: %d"), GetLastError()); 
         return 5; 
        } 
    } 
    
相關問題