2017-07-07 58 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; 
        } 
    } 
    
相关问题