tags:

views:

282

answers:

3

How do you register a COM object written in Managed C++ to be SingleUse? Regasm does not appear to have the option. I am guessing it may be a s simple as defining an attribute in AssemblyInfo.cpp but I can't find it.

I have written a VB6 ActiveX EXE and it works as I want it to - that is every request for an Interface creates a new running Server.

Do I have to resort to wrapping my Managed C++ COM in VB6? There has to be an easier way.

A: 

How to use single or multiple instances of an OLE object in MFC by using Visual C++

http://support.microsoft.com/kb/141154

Robert Harvey
Unfortunately we are not using MFC. It is only Managed c++.
David Gray Wright
A: 

This might give you some clues:

Using Managed Controls as ActiveX Controls
http://blogs.msdn.com/andreww/archive/2008/11/24/using-managed-controls-as-activex-controls.aspx

Robert Harvey
Interesting article but does not mention the single use aspect I am after.
David Gray Wright
Are you referring to a Single-Threaded Apartment (STA) such as the one you would get if you wrapped it in a VB EXE?
Robert Harvey
Surely there's a straightforward way to set that in C++.
Robert Harvey
I want a COM server running per interface...Been asking at Microsoft as well and they recommend http://www.codeproject.com/KB/COM/BuildCOMServersInDotNet.aspx . There has to be an easier way of doing it.
David Gray Wright
+1  A: 

It looks like Serviced Components holds the key to my problem.

http://oreilly.com/catalog/comdotnetsvs/chapter/ch10.html

Once I derive from ServicedComponent in the System.EnterpriseServices namespace, do a regsvcs on the dll and then change the pooling in dcomcnfg to be greater than one - it all works. Another issue is to have the Managed C++ component being regsistered compiled with /clr:pure not just /clr. I have yet to complete the project but sample projects I built on the way indicate it should work this way. I think I will wrap my Managed C++ solution in a C# assembly...

Now that i have nearly finished the project one more thing...You need to be on a Server O\S to get the pooling to work.

Thanks for your guidance...

David Gray Wright