简体   繁体   English

将COM服务器添加到COM +服务器应用程序后,无法再在过程中实例化它-为什么?

[英]Once I add a COM server into a COM+ server application I can no longer instantiate it in-proc - why?

I have a 32-bit COM server DLL and need to use it from both 32-bit and 64-bit applications. 我有一个32位COM服务器DLL,需要从32位和64位应用程序中使用它。 I can create a COM+ server application and then the COM server will be instantiated in a surrogate process. 我可以创建一个COM +服务器应用程序,然后在代理过程中实例化该COM服务器。

The problem is I can no longer instantiate it as an in-proc server ( CLSCTX_INPROC_SERVER flag passed to CoCreateInstance() ) - I get "class not registered". 问题是我无法再将其实例化为CLSCTX_INPROC_SERVER服务器(传递给CoCreateInstance() CLSCTX_INPROC_SERVER标志)-我得到“类未注册”。 This is not very good, because now even 32-bit applications need to talk to the surrogate process and this adds unnecessary marshalling overhead. 这不是很好,因为现在甚至32位应用程序都需要与代理进程进行对话,这会增加不必要的编组开销。

How can I set up a COM+ server application in such way that clients of same bitness can still use the COM server in-proc? 如何以相同位数的客户端仍可以在过程中使用COM服务器的方式设置COM +服务器应用程序?

32-bit DLLs can only be loaded in 32-bit processes, and 64-bit DLLs in 64-bit processes (reasons are different pointer sizes, but also calling conventions). 32位DLL只能在32位进程中加载​​,而64位DLL只能在64位进程中加载​​(原因是指针大小不同,但调用约定也不同)。 So it is not possible to use a COM object from a 32-bit in-process server DLL in a 64-bit application, because the system will not load the DLL. 所以,不可能在一个64位应用使用来自32位的进程内服务器DLL一个COM对象,因为系统将不加载的DLL。 Windows Registry also has two different views, one for 64-bit apps and one for 32-bit apps. Windows注册表也有两种不同的视图,一种用于64位应用程序,另一种用于32位应用程序。 Your library and interfaces and coclasses from the 32-bit DLL are registered in the 32-bit view, so they are not visible to the 64-bit apps, that's why you get that message. 您的库以及来自32位DLL的接口和协类已在32位视图中注册,因此它们对64位应用程序不可见,这就是为什么收到此消息的原因。

You need a workaround for that, and the most simple workaround is to create a 32-bit out-of-process executable that hosts a wrapper COM, that acts as a proxy (or facade) for the former COM object. 为此,您需要一种解决方法,最简单的解决方法是创建一个32位进程外可执行文件,该可执行文件承载一个包装COM,该包装COM充当前一个COM对象的代理(或立面)。 In your 64-bit application you will use this new wrapper. 在您的64位应用程序中,您将使用此新包装器。 You can read more about that here: http://www.dnjonline.com/article.aspx?id=jun07_access3264 . 您可以在这里阅读有关此内容的更多信息: http : //www.dnjonline.com/article.aspx?id=jun07_access3264

That is probably related to COM+, which keeps a cache of recently activated objects. 这可能与COM +有关,后者保留了最近激活的对象的缓存。 See the comments below this article . 请参阅本文下面的评论。

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

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