简体   繁体   English

windows 能否区分 32 位和 64 位 DLL?

[英]Can windows distinguish 32-bit and 64-bit DLLs?

Should Windows applications generally be able to distinguish between two DLLs with the same name, one being 32-bit and one being 64-bit, if they're in two separate paths in the system PATH variable? Windows 应用程序是否应该能够区分两个同名的 DLL,一个是 32 位,一个是 64 位,如果它们位于系统 PATH 变量中的两个单独路径中?

Specifically right now, I have 32-bit and 64-bit DLLs for FreeImage, and they're in two separate folders, free_image_path\dist32 and free_image_path\dist64 , both of which I've added to the system PATH.特别是现在,我有用于 FreeImage 的 32 位和 64 位 DLL,它们位于两个单独的文件夹中, free_image_path\dist32free_image_path\dist64 ,我已将这两个文件夹添加到系统 PATH 中。 However, application built to use them can't find either and I'm wondering if this is because there's two DLLs with the same name and they can't distinguish them.但是,为使用它们而构建的应用程序也找不到,我想知道这是否是因为有两个同名的 DLL 并且它们无法区分它们。

I also tried putting the 32-bit and 64-bit DLLs in the windows\system and windows\SySWoW64 folders respectively, and that worked for the 32-bit app but not the 64-bit.我还尝试将 32 位和 64 位 DLL 分别放在 windows\system 和 windows\SySWoW64 文件夹中,这适用于 32 位应用程序,但不适用于 64 位。

Thanks.谢谢。

Windows can tell whether a given DLL is compiled for 32 bit or 64 bit platforms, but that won't help in the situation you describe. Windows 可以判断给定的 DLL 是针对 32 位还是 64 位平台编译的,但这对您描述的情况没有帮助。 The DLL loader for your app process will stop looking as soon as it finds a DLL in the system path that fits the file name requirements for the DLL import.一旦在系统路径中找到符合 DLL 导入文件名要求的 DLL,您的应用程序进程的 DLL 加载程序将停止查找。 There are no other qualifications for matching code DLLs.匹配代码DLL 没有其他条件。 (as noted in the comments, non-code resource DLLs are a different story. I suspect resource DLLs are not loaded by the core program loader but by a resource manager with different rules and objectives.) (如评论中所述,非代码资源 DLL 是另一回事。我怀疑资源 DLL 不是由核心程序加载器加载,而是由具有不同规则和目标的资源管理器加载。)

If the first DLL in the path is 32 bit and your app is 32 bit, then the DLL load will work.如果路径中的第一个 DLL 是 32 位,而您的应用程序是 32 位,则 DLL 加载将起作用。 If the app is 64 bit, it will fail to load the DLL and the process will abort.如果应用程序是 64 位,它将无法加载 DLL 并且进程将中止。

If you want two DLLs to coexist on the system path, you need to give them unique file names.如果您希望两个 DLL 在系统路径上共存,您需要为它们指定唯一的文件名。

As an alternative to putting the 64-bit dll in \windows\system32 and the 32-bit one in \windows\syswow64 , I have found that it also works if you put the 32-bit one in a subdirectory of \Program Files (x86) and the 64-bit one in the corresponding subdirectory of \Program Files , with both of those subdirectories included in PATH.作为将 64 位 dll 放在\windows\system32和 32 位放在\windows\syswow64的替代方法,我发现如果将 32 位放在\Program Files (x86)\Program Files的相应子目录中的 64 位版本,这两个子目录都包含在 PATH 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM