某些 Windows DLL 显然如何同时支持 32 位和 64 位?

How do certain Windows DLL apparently manage to support both 32 and 64 bit?

我似乎能够从 32 位或 64 位应用程序访问 C:\WINDOWS\system32\opengl32.dll(以及 C:\WINDOWS\system32\glu32.dll)中的函数(对于它的价值,我是通过 ctypes 模块从单独的 32 位和 64 位 Python 2.7 解释器执行此操作。

有了glut32.dll,情况就不一样了。它只是作为 GraphViz 的 32 位安装的一部分出现在我的 Path 上。从 32 位 Python,我可以 link 动态到它,但是从 64 位 Python 我得到 [Error 193] %1 is not a valid Win32 application.

现在,这个错误并不让我感到惊讶,因为我一直认为 DLL 必须在 Windows 上提交到一种或另一种体系结构(特别是, 好像是这么说的)。令我惊讶的是第一种情况 缺少 错误...... opengl32.dll 是如何做到的,以及如何在构建自己的 DLL 时复制此行为?

在 64 位系统上,只有 64 位进程使用 c:\Windows\System32\opengl32.dll。对于 32 位进程系统重定向 c:\Windows\System32\opengl32.dllc:\Windows\SysWOW64\opengl32.dll.

File System Redirector

In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64. Access to %windir%\lastgood\system32 is redirected to %windir%\lastgood\SysWOW64. Access to %windir%\regedit.exe is redirected to %windir%\SysWOW64\regedit.exe.