CoCreateInstance在.NET中精确匹配?

我有进程(DLL)的COM服务器,但我解决了作为DllSurrogate运行,由于这个原因从非托pipe代码(delphi)我有:

function TComWrapper.GetServer: IUnknown; begin OleCheck(CoCreateInstance(ServerData^.ClassId, nil, CLSCTX_LOCAL_SERVER, IUnknown, Result)); end; 

从C#使用现在:

 [DllImport("ole32.dll", EntryPoint = "CoCreateInstance", CallingConvention = CallingConvention.StdCall)] static extern UInt32 CoCreateInstance([In, MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, IntPtr pUnkOuter, UInt32 dwClsContext, [In, MarshalAs(UnmanagedType.LPStruct)] Guid riid, [MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject); 

  UInt32 dwRes = CoCreateInstance(ClassIdGuid, IntPtr.Zero, (uint)(CLSCTX.CLSCTX_LOCAL_SERVER), //if OR with CLSCTX_INPROC_SERVER then INPROC Server will be created, because of DLL COM Server IUnknownGuid, out instance); 

上面的代码是不安全的。 CoCreateInstance上面是否存在安全版本? 看来, Activator.CreateInstance不帮助我。 我必须显式设置运行上下文(第三个参数)

Solutions Collecting From Web of "CoCreateInstance在.NET中精确匹配?"