2

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.

Ant Waters
  • 510
  • 1
  • 5
  • 22
  • Why don't you use Component Services (instead of wiring surrogates manually, you'll have a whole framework to do) and Application pooling: https://learn.microsoft.com/en-us/windows/desktop/cossdk/com--application-pooling-concepts – Simon Mourier Jan 30 '19 at 16:47
  • It's a windows desktop application, installed locally on a pc using a setup. Like installing Word or Excel. I don't know much about it but COM+ and Application Pooling sounds a bit over the top and an installation / management headache? – Ant Waters Jan 30 '19 at 18:11
  • I don't think it's over the top of anything. IMHO, it does the same thing (it's also a surrogate using dllhost.exe) but with lots of value added, and w/o manual registry config or anything. It's a 20-years old Windows component. It just happens that many people - maybe like the article author - don't know it's there. I've detailed an example here: https://stackoverflow.com/a/54128090/403671 (you don't have to look the details that are about security, this was for the question only) – Simon Mourier Jan 31 '19 at 11:12
  • Note you already have an exe. In this case, you can't use Component Services. You would need to transform that into a .dll with the same services. – Simon Mourier Jan 31 '19 at 11:16

0 Answers0