我应该如何命名以 32 位和 64 位形式分发的本机 DLL?
我有一个商业产品,它是 DLL(本机 32 位代码),现在是时候构建它的 64 位版本了。因此,在 64 位 Windows 上安装时,32 位版本进入 Windows\SysWOW64,64 位版本进入... Windows\System32! (这里我已经咬到舌头了……) 或者,DLL 可以与客户端应用程序一起安装。
我应该为 64 位 DLL 命名什么?
与 32 位同名:两个文件执行相同的操作,具有相同的名称,但完全不可互换。这不是造成混乱和支持问题的原因吗?
不同的名称(例如product.dll和product64.dll):现在客户端应用程序必须知道它们运行的是32位还是64位才能引用我的DLL,并且有些语言只有在运行时才能知道 - time - .NET 只是一个例子。现在,所有静态编译的客户端都必须对导入声明进行条件化: IF target=WIN64 THEN import Blah from "product64.dll" ELSE import Blah from "product.dll" ENDIF
该产品包含大量 C 代码和一大块C++ 的 - 将其移植到 C# 不是一个选项。
建议?建议?
I have a commercial product that's a DLL (native 32-bit code), and now it's time to build a 64-bit version of it. So when installing on 64-bit Windows, the 32-bit version goes into Windows\SysWOW64, and the 64-bit version goes into... Windows\System32! (I'm biting my tongue here...)
Or the DLL(s) can be installed alongside the client application.
What should I name the 64-bit DLL?
Same name as 32-bit: Two files that do the same thing, have the same name, but are totally non-interchangeable. Isn't that a recipe for confusion and support problems?
Different names (e.g. product.dll and product64.dll): Now client applications have to know whether they are running 32-bit or 64-bit in order to reference my DLL, and there are languages where that isn't known until run-time - .NET being just one example. And now all the statically compiled clients have to conditionalize the import declarations: IF target=WIN64 THEN import Blah from "product64.dll" ELSE import Blah from "product.dll" ENDIF
The product contains massive amounts of C code, and a large chunk of C++ - porting it to C# is not an option.
Advice? Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
客户端应用程序不必“知道”它们是 32 位还是 64 位。操作系统自动从适当的位置加载DLL,因为不可能将32位DLL加载到64位进程中,也不可能将64位DLL加载到32位进程中。
如果 32 位应用程序尝试从 system32 加载某些内容,操作系统会默默地将其重定向到 SysWow64 目录,强制加载 32 位版本。
通过使用不同的名称,你就击败了整个机制。专门为允许您使用相同名称而构建的机制。
Client applications do not have to "know" they are 32 bit or 64 bit. The OS automatically loads DLLs from the appropriate location because it is not possible to load a 32 bit DLL into a 64 bit process, and it is not possible to load a 64 bit DLL into a 32 bit process.
If a 32 bit application tries to load something from system32, the OS will silently redirect it to the SysWow64 directory, forcing the 32 bit version to load.
By having different names, you defeat this whole mechanism. A mechanism built specifically to allow you to use the same name.
为什么不在 dll 前面加上下划线...例如 product_32.dll 和 product_64.dll?或者通过使用平台前缀 - product_x86_32.dll 和 product_x86_64.dll 来指示这一点?至少这会消除 DLL 命名的混乱......你觉得怎么样?
Why not prefix the dll's with an underscore ... such as product_32.dll and product_64.dll? OR indicated this by using a platform prefix - product_x86_32.dll and product_x86_64.dll? At least that will clear the confusion of the naming of the DLL... What do you think?
我决定在这方面遵循 Microsoft 的做法,当 System32 中的 DLL 进入 64 位时,他们保留了相同的名称。在Win7/64上,System32\avicap32.dll是一个64位DLL!
我自己和我可能会感到一些困惑。我的客户拥有同名的 32 位和 64 位 DLL。然而,我认为让我的所有客户都必须使其代码字宽敏感会更糟糕。尤其是 .NET 开发人员,他们通常可以将目标平台设置为“AnyCPU”。
I've decided to follow Microsoft on this, who have kept the same names for the DLLs in System32 when they went to 64-bit. On Win7/64, System32\avicap32.dll is a 64-bit DLL!
There is some potential confusion for myself & my customers, having 32-bit and 64-bit DLLs with the same name. However I think it would be worse to have all my customers have to make their code word-width sensitive. Especially the .NET developers, who can often leave their target platform set to 'AnyCPU'.
某些调用 DLL 的语言具有根据调用应用程序位数调整其名称的机制。
例如,在LabVIEW中,当使用以下两种模式之一时,DLL名称可以自动调整:
MyDll*.dll
将在win32上转换为MyDll32.dllMyDll64.dll。MyDll**.dll
将在 win32 上转换为 MyDll.dll,在 win64 上转换为 MyDll_64.dll(注意下划线)。因此,以 32 位和 64 位二进制形式分发的本机 DLL 的建议命名方案是:
| | WIN32 | win64 |
|:--------- |:-------------|:---------------|
|方案一|
MyDll32.dll
|MyDll64.dll
||方案2|
MyDll.dll
|MyDll_64.dll
|如果两个 DLL 必须位于同一个文件夹中(例如与应用程序一起),则使用不同的名称会很有用。
注意:如果您不需要使用不同的名称,我同意 doug65536的回答。如果您将 DLL 安装在 Windows 系统文件夹(SysWOW64 和 System32)中,则最好对这两个位数使用相同名称
MyDll.dll
,并让 Windows 在以下情况下发挥其魔力:需要。Some languages that call DLLs have a mechanism to adapt their names according to the calling application bitness.
For example in LabVIEW, the DLL name can be automatically adapted when using one of two patterns:
MyDll*.dll
will translate on win32 to MyDll32.dll and on win64 to MyDll64.dll.MyDll**.dll
will translate on win32 to MyDll.dll and on win64 to MyDll_64.dll (notice the underscore).So a suggested naming scheme for native DLL, distributed in both 32-bit and 64-bit binary form is:
| | win32 | win64 |
|:--------- |:--------------|:---------------|
| Scheme 1 |
MyDll32.dll
|MyDll64.dll
|| Scheme 2 |
MyDll.dll
|MyDll_64.dll
|Having different names can be useful if both DLLs must be in the same folder - alongside the application for example.
Note: if you do not need to have different names, I agree with the answer of doug65536. If you install the DLLs in windows system folders (SysWOW64 and System32), you are better off using the same name
MyDll.dll
for both bitnesses and let Windows do its magic when needed.