I need to implement an out-ofproc server in C#. The basic server part is done and the server is accessible by progid like this: "someNamespace.someClassname".
But now i want something like this: "progid:Application(set=somevalue)".
Is there any way to do this in C#?
Up to now I register a factory and this factory returns the com object.
Guid appClsId = new Guid(ComCst.ApplicationId);
int hRes = ComNtv.CoRegisterClassObject(ref appClsId, new ApplicationFac(),
CLSCTX.LOCAL_SERVER, REGCLS.MULTIPLEUSE | REGCLS.SUSPENDED, out cokAppObj);
if (hRes != 0)
{
throw new ApplicationException(
"CoRegisterClassObject failed w/err 0x" + hRes .ToString("X"));
}
hRes = ComNtv.CoResumeClassObjects();
if (hRes != 0)
{
if (cokAppObj!= 0)
{
ComNtv.CoRevokeClassObject(cokAppObj);
}
throw new ApplicationException(
"CoResumeClassObjects failed w/err 0x" + hRes .ToString("X"));
}
And this is the CreateInstance Method in the factory.
public int CreateInstance(IntPtr pUnkOuter, ref Guid riid,
out IntPtr ppvObject)
{
ppvObject = IntPtr.Zero;
if (pUnkOuter != IntPtr.Zero)
{
Marshal.ThrowExceptionForHR(ComCst.CLASS_E_NOAGGREGATION);
}
if (riid == new Guid(ComCst.ApplicationId) ||
riid == new Guid(ComCst.IID_IDispatch) ||
riid == new Guid(ComCst.IID_IUnknown))
{
IntPtr ptr = Marshal.GetComInterfaceForObject(
new Application(), typeof(IApplication));
ppvObject = ptr;
}
else
{
Marshal.ThrowExceptionForHR(ComCst.E_NOINTERFACE);
}
return 0;
}
Info: There is an already implemented c++ in-proc com server, which is creating an object and register it in the running object table. This server than returns a moniker to the client. Is it possible to accomblish this in C#?