简体   繁体   English

如何安装COM DLL的32位和64位版本并“自动选择”?

[英]How do I install both 32-bit and 64-bit versions of a COM DLL and “auto-select”?

We've got a DLL (a COM server) that will compile fine in 32-bit and 64-bit, but the DLL uses the same CLSID and AppID for the 32-bit version and the 64-bit version. 我们有一个DLL(一个COM服务器)可以在32位和64位编译,但DLL使用相同的CLSID和AppID 32位版本和64位版本。 Is this OK or does this have to change? 这样可以,还是必须改变?

I'm asking this because apparently on a 64-bit machine, we can't register the 32-bit version and the 64-bit version together. 我问这个是因为显然在64位机器上,我们无法将32位版本和64位版本注册在一起。 It would be nice if 32-bit client applications could automatically use the 32-bit DLL, and 64-bit client applications could automatically use the 64-bit DLL. 如果32位客户端应用程序可以自动使用32位DLL,并且64位客户端应用程序可以自动使用64位DLL,那将是很好的。

On a related note, we have the source code and Visual Studio 2005 project file for a client application ... how do we compile a 32-bit and 64-bit version of the same application? 在相关的说明中,我们有客户端应用程序的源代码和Visual Studio 2005项目文件...我们如何编译同一应用程序的32位和64位版本? It's a C# application, and it includes a reference to our COM server DLL like this: 它是一个C#应用程序,它包含对我们的COM服务器DLL的引用,如下所示:

<ItemGroup> <COMReference Include="ComServer">

<Guid>{C1FADEA6-68FD-4F43-9FC2-0BC451FA5D53}</Guid>

<VersionMajor>830</VersionMajor> <VersionMinor>0</VersionMinor>

<Lcid>0</Lcid> <WrapperTool>tlbimp</WrapperTool> <Isolated>False</Isolated>

</COMReference> </ItemGroup>

If it turns out that we need a separate CLSID for 64-bit, how do we make this reference "only for the 32-bit configuration" in Visual Studio? 如果事实证明我们需要一个单独的64位CLSID,我们如何在Visual Studio中“仅针对32位配置”进行此引用? Or do we have to have separate projects with the same source code: one that refers to 32-bit DLL, and the other that refers to 64-bit DLL? 或者我们必须有相同的源代码的单独项目:一个引用32位DLL,另一个引用64位DLL?

Both versions can (and indeed should) use the same GUIDs for everything. 两个版本都可以(实际上应该)为所有内容使用相同的GUID。

On a 32-bit machine you can't register or use the 64-bit DLL, so there's no problem there. 在32位机器上,您无法注册或使用64位DLL,因此没有问题。 The 64-bit DLL simply doesn't enter the picture. 64位DLL根本不进入图片。

On a 64-bit machine the 64-bit DLL gets registered in HKLM/Software/Classes/CLSID (etc.) and the 32-bit DLL gets registered in HKLM/Software/Wow6432Node/Classes/CLSID. 在64位计算机上,64位DLL在HKLM / Software / Classes / CLSID(等)中注册,32位DLL在HKLM / Software / Wow6432Node / Classes / CLSID中注册。 (I wonder where you got the advice that you can't register the 32-bit DLL on a 64-bit machine...) A 32-bit client running on the 64-bit machine will look in the normal place in the registry, but the OS will silently redirect it to the Wow6432Node key instead. (我想知道你在哪里得到的建议是你不能在64位计算机上注册32位DLL ...)在64位计算机上运行的32位客户端将在注册表中的正常位置查找,但操作系统将默默地将其重定向到Wow6432Node键。

This is dealt with inside Windows with a feature called ' Registry redirection ' On the 64-bit version of Windows, a 32-bit program gets a different view of the registry. 这是在Windows内部处理的,具有称为“ 注册表重定向 ”的功能在64位版本的Windows上,32位程序获得了不同的注册表视图。 Any access to the HKCR alias or the HKLM\\Software root is redirected for the kind of keys that a COM server uses. 对于COM服务器使用的密钥类型,将重定向对HKCR别名或HKLM \\ Software根目录的任何访问权限。 A 32-bit program actually sees the key values stored in HKLM\\Software\\Wow6432Node. 32位程序实际上看到存储在HKLM \\ Software \\ Wow6432Node中的键值。 You can see it with Regedit.exe 您可以使用Regedit.exe查看它

This is normally taken care of by an installer, a VS Setup project has the TargetPlatform property for example. 这通常由安装程序处理,VS Setup项目具有TargetPlatform属性。 If you want to make the COM server available in both 32-bit and 64-bit mode then you should use two installers. 如果要在32位和64位模式下使COM服务器可用,则应使用两个安装程序。 Or a 64-bit installer that writes both sets of keys. 或者是一个写入两组密钥的64位安装程序。 Having a COM server that can handle both is very unusual in the olden days. 拥有可以处理两者的COM服务器在过去很不寻常。 But not unheard of when you implemented in .NET for example. 但是,当您在.NET中实现时,并非闻所未闻。

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

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