How do I make COM Surrogate Multiple Instance?

2019-08-29 09:30发布

I have a C# 32-bit COM DLL that talks to a C# 64-bit exe using the 'DllSurrogate' method described in Hosting a .NET DLL as an Out-Of-Process COM Server (EXE).

I need this setup because the 32 bit C# talks to a legacy 32-bit C++ dll.

I thought everything was working fine, but I have just realised that when you create a second instance of the 64-bit exe you do not get a second "DLL Host" (COM Surrogate) process. This is no good for my application.

This is a Windows Desktop application and I need to know that if the user starts it multiple times they all run in their own separate processes. Otherwise, data in the legacy dll might be corrupted and they will certainly run into the 32-bit process memory limitation.

The surrogate is registered using the AppId DllSurrogate key.

The 32-bit class instance is created in the 64-bit exe by a call to CoCreateInstance.

From some Googling it seems that the solution to my problem should involve the REGCLS_SINGLEUSE key from the REGCLS Enumeration. However, I can't see where to supply that key. Also, I note that in this enumeration there is a separate REGCLS_SURROGATE key. I hope that doesn't mean that DLL Surrogate and Single Use are mutually exclusive!

Any ideas would be welcome.

0条回答
登录 后发表回答