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 becaus
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:
.H-part:
\#include < vcclr.h >
\#using < MyCSharpModule.dll >
using namespace System;
class ATL_NO_VTABLE MyCSharpProxyServer :
public CComObjectRootEx< CComMultiThreadModel >,
.....
{
HRESULT FinalConstruct();
STDMETHODIMP LoadMyFile(BSTR FileName);
.....
gcroot m_CSClass;
}
.CPP-part:
using namespace System::Collections;
using namespace MyCSNamespace;
HRESULT MyCSharpProxyServer::FinalConstruct()
{
m_CSClass = gcnew MyCSharpClass();
}
STDMETHODIMP MyCSharpProxyServer::LoadMyFile(BSTR FileName)
{
try {
int hr = m_CSClass->LoadFile(gcnew String( FileName));
return hr;
}
catch( Exception^ e ) {
return E_FAIL;
}
}
The C# part (MyCSharpClass class) lives in a separate project with output type Class Library.