I need to create an out-of-process COM server (.exe) in C# that will be accessed by multiple other processes on the same box. The component has to be a single process because it will cache the information it provides to its consumers in memory.
Note: the processes that will access my COM Server are mostly Matlab processes, thus the necessity for a COM interface.
I have seen threads regarding creating in-process COM components in .Net on stack overflow (Create COM ...) and on the web, but am having a hard time to find a way to create out-of-process components with .Net.
How is this achievable? Any suggested references?
Thanks.
It could be done using umanaged ATL framework and plumbing it with the managed code (simple by changing the result project properties to /clr).
Here are illustrative snippets:
The C# part (MyCSharpClass class) lives in a separate project with output type Class Library.
ActiveX.NET, is a true Out-Of-Proc (EXE) COM Server implementation in C#.NET. This one has a cleaner implementation compared to the original CSExeCOMServer, published in Code.MSDN.
ActiveX.NET has features like it does use a .NET Message Pump (instead of native) and uses MEF Plugin model, so that the EXE Server is decoupled and can be shared among multiple COM Plugins, which can be developed independently
The visual studio project "CSExeCOMServer" that you can find here (All-in-One), gives a full example.
Use the flag REGCLS_MULTIPLEUSE with CoRegisterClassObject() to make the coclass a multiuse class. Here is more info: http://support.microsoft.com/kb/169321.
IMO, one of the ways through which this can be done is to create a normal COM Dll as per the method you mentioned in the link and then after registering your COM dll, change it to a surrogate DLL. This can be done very easily through OLEView utility, although you can do it manually as well by changing registry entries as well through the method mentioned at http://msdn.microsoft.com/en-us/library/ms686606(VS.85).aspx.
By making this a surrogate DLL, it will run in it's own dllhost.exe and hence will be out-of-process.
You can use RegistrationServices.RegisterTypeForComClients, which is the managed equivalent of CoRegisterClassObject - for sample code see here.