将 32 位路径转换为其 WOW64 等效路径

发布于 2024-07-22 03:28:17 字数 501 浏览 9 评论 0原文

我可以在 32 位应用程序中调用任何函数来将它认为正在使用的路径转换为它实际使用的路径吗? (例如,调用它将 Program Files 中的文件夹路径转换为 ​​Program Files (x86) 中的路径,或者在 64 位系统上运行时反之亦然。)我需要这样做,以便当用户当在 GUI 中显示一个目录时(如浏览文件或目录时),他看到的是真实的目录,而不是应用程序本身认为它看到的目录。

我们需要同时支持 32 位和 64 位 Windows,因此这应该可以在这两种环境中工作。

编辑 处理WOW64的需要在于我的应用程序是安装程序的引导应用程序。 默认情况下,该产品在 32 位系统上安装在 Program Files 下,而在 64 位系统上,它安装在 Program Files (x86) 下。 让用户选择安装产品的位置(包括完全不同的硬盘驱动器,如果这是他想要或需要的)的对话; 并且它必须在两种环境下都能正常工作。 目前,即使在 64 位系统上,它也始终显示(并浏览)程序文件。

Is there any function that I can call to in a 32-bit app that would convert the paths that it thinks it's using to and from the paths that it's actually using? (For instance, call it to convert the path for a folder in Program Files to a path in Program Files (x86) or vice versa when running on a 64-bit system.) I need to do this so that, when the user is presented with a directory in the GUI (as when browsing for files or directories), he sees the real directory, rather than what the app itself thinks it sees.

We need to support both 32- and 64-bit Windows, so this should work in both environments.

Edit The need to deal with WOW64 lies in the fact that my app is the bootstrap application of an installer. By default, the product is installed under Program Files on a 32-bit system, while on a 64-bit system, it's installed under Program Files (x86). The dialogue that lets the user choose where to install the product (including on a different hard drive altogether if that's what he wants or needs); and it must work properly in both environments. Currently, it's always displaying (and browsing in) Program Files, even on 64-bit systems.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-07-29 03:28:17

浏览 Program Files 和 Windows\System32 是您的应用程序的用例吗? 我鼓励您放弃解决这个问题,因为它变得非常难看。 要么完全留在 32 位世界,要么重新编译为 x64。 生活在 WOW64 的“中间”世界将使您的代码变得更加复杂。

如果您确实想这样做,http://msdn .microsoft.com/en-us/library/aa365743(VS.85).aspx 就可以了。

Is browsing through Program Files and Windows\System32 a use-case for your app? I encourage you to abandon solving this problem, as it gets really ugly. Either stay all in the 32-bit world, or recompile for x64. Living in the "in-between" world of WOW64 will make your code much more complex.

If you really want to do this, http://msdn.microsoft.com/en-us/library/aa365743(VS.85).aspx will do the trick.

缱绻入梦 2024-07-29 03:28:17

这里我有一个禁用 wow64 重定向的工作示例:

BOOL CCopyUtils::CopyServiceFiles(CAtlString szSourceDir, CAtlString szTargetDir)
{
    BOOL bResult = TRUE;
    TCHAR szSource[MAX_PATH];
    TCHAR szDest[MAX_PATH];
    TCHAR szSourceFile[MAX_PATH];
    TCHAR szDestFile[MAX_PATH];

    HINSTANCE hDll;
    PVOID OldValue;
    Wow64DisableWow64FsRedirection pfWow64DisableWow64FsRedirection=NULL;
    Wow64RevertWow64FsRedirection pfWow64RevertWow64FsRedirection=NULL;

    hDll=LoadLibrary("Kernel32.dll");
    ATLASSERT(hDll!=NULL);

    pfWow64DisableWow64FsRedirection=(Wow64DisableWow64FsRedirection)GetProcAddress(
        hDll, "Wow64DisableWow64FsRedirection");
    // http://msdn.microsoft.com/en-us/library/aa365745(VS.85).aspx
    pfWow64RevertWow64FsRedirection=(Wow64RevertWow64FsRedirection)GetProcAddress(
        hDll, "Wow64RevertWow64FsRedirection");

    if(pfWow64DisableWow64FsRedirection==NULL)
        ATLTRACE(_T("Function 'Wow64DisableWow64FsRedirection' not loaded."));
    else if((pfWow64DisableWow64FsRedirection)(&OldValue)==TRUE)
        ATLTRACE(_T("Wow64 filesystem redirecton disabled."));
    else 
        ATLTRACE(_T("Wow64 filesystem redirecton not disabled."));

    if (_taccess(szTargetDir, 0) != 0)
        _tmkdir(szTargetDir);

    DeleteOldFiles(szTargetDir);

    int  i = 0;
    _tcscpy(szSource, szSourceDir);
    if (szSource[_tcslen (szSource) -1] != '\\')
        _tcscat (szSource,"\\");    

    _tcscpy(szDest, szTargetDir);
    if (szDest[_tcslen (szDest) -1] != '\\')
        _tcscat (szDest,"\\");    

    while (m_ServiceFiles[i] != NULL)
    {
        _tcscpy(szSourceFile, szSource);
        _tcscat(szSourceFile, m_ServiceFiles[i]);

        _tcscpy(szDestFile, szDest);
        _tcscat(szDestFile, m_ServiceFiles[i]);

        if (!CopyFile(szSourceFile, szDestFile, FALSE))     
        {
            bResult = FALSE;
            ATLTRACE(_T("Error coping %s to %s\n"), szSourceFile, szDestFile);
            ATLASSERT(FALSE);                   
            break;
        }
        i++;
    }

    if(pfWow64RevertWow64FsRedirection==NULL)
        ATLTRACE(_T("Function 'pfWow64RevertWow64FsRedirection' not loaded."));
    else if((pfWow64RevertWow64FsRedirection)(OldValue)==TRUE)
        ATLTRACE(_T("Wow64 filesystem redirecton restored."));
    else 
        ATLTRACE(_T("Wow64 filesystem redirecton not restored."));
    FreeLibrary(hDll);

    return bResult;
}

最好的问候

Here I have a working sample of disablig wow64 redirection:

BOOL CCopyUtils::CopyServiceFiles(CAtlString szSourceDir, CAtlString szTargetDir)
{
    BOOL bResult = TRUE;
    TCHAR szSource[MAX_PATH];
    TCHAR szDest[MAX_PATH];
    TCHAR szSourceFile[MAX_PATH];
    TCHAR szDestFile[MAX_PATH];

    HINSTANCE hDll;
    PVOID OldValue;
    Wow64DisableWow64FsRedirection pfWow64DisableWow64FsRedirection=NULL;
    Wow64RevertWow64FsRedirection pfWow64RevertWow64FsRedirection=NULL;

    hDll=LoadLibrary("Kernel32.dll");
    ATLASSERT(hDll!=NULL);

    pfWow64DisableWow64FsRedirection=(Wow64DisableWow64FsRedirection)GetProcAddress(
        hDll, "Wow64DisableWow64FsRedirection");
    // http://msdn.microsoft.com/en-us/library/aa365745(VS.85).aspx
    pfWow64RevertWow64FsRedirection=(Wow64RevertWow64FsRedirection)GetProcAddress(
        hDll, "Wow64RevertWow64FsRedirection");

    if(pfWow64DisableWow64FsRedirection==NULL)
        ATLTRACE(_T("Function 'Wow64DisableWow64FsRedirection' not loaded."));
    else if((pfWow64DisableWow64FsRedirection)(&OldValue)==TRUE)
        ATLTRACE(_T("Wow64 filesystem redirecton disabled."));
    else 
        ATLTRACE(_T("Wow64 filesystem redirecton not disabled."));

    if (_taccess(szTargetDir, 0) != 0)
        _tmkdir(szTargetDir);

    DeleteOldFiles(szTargetDir);

    int  i = 0;
    _tcscpy(szSource, szSourceDir);
    if (szSource[_tcslen (szSource) -1] != '\\')
        _tcscat (szSource,"\\");    

    _tcscpy(szDest, szTargetDir);
    if (szDest[_tcslen (szDest) -1] != '\\')
        _tcscat (szDest,"\\");    

    while (m_ServiceFiles[i] != NULL)
    {
        _tcscpy(szSourceFile, szSource);
        _tcscat(szSourceFile, m_ServiceFiles[i]);

        _tcscpy(szDestFile, szDest);
        _tcscat(szDestFile, m_ServiceFiles[i]);

        if (!CopyFile(szSourceFile, szDestFile, FALSE))     
        {
            bResult = FALSE;
            ATLTRACE(_T("Error coping %s to %s\n"), szSourceFile, szDestFile);
            ATLASSERT(FALSE);                   
            break;
        }
        i++;
    }

    if(pfWow64RevertWow64FsRedirection==NULL)
        ATLTRACE(_T("Function 'pfWow64RevertWow64FsRedirection' not loaded."));
    else if((pfWow64RevertWow64FsRedirection)(OldValue)==TRUE)
        ATLTRACE(_T("Wow64 filesystem redirecton restored."));
    else 
        ATLTRACE(_T("Wow64 filesystem redirecton not restored."));
    FreeLibrary(hDll);

    return bResult;
}

Best regards

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文