Click here to Skip to main content
15,742,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello I wrote a managed COM server and COM client in C#. When I’m trying to get a reference to a COM server in a COM client by using this code.
Type comType = Type.GetTypeFromProgID("My.ComServer", true);
object comObj = Activator.CreateInstance(comType);
var comServer = (ComServer)comObj;

I get a reference to the new object instead of a reference to a registered COM server in ROT. To fix this problem, I use pinvoke CoGetClassObject it works but I have another problem.
private void InitComServer(object sender, RoutedEventArgs e)
            object comServerInstance = null;

            var factory = Ole32NativeMethods.CoGetClassObject(typeof(TestCoClass).GUID, RegistrationClassContext.LocalServer, IntPtr.Zero, typeof(IClassFactory).GUID) as IClassFactory;

            if (factory != null)
                var iid = typeof(ITestInterface).GUID;
                factory.CreateInstance(null, iid, out comServerInstance);

            this.comServer = (ITestInterface)comServerInstance;

I don’t know how to subscribe to events of COM server.

P.S. I attached a small demo application to illustrate this problem.
Sergey Alexandrovich Kryukov 2-Dec-14 11:11am    
Let me tell you: if both client and server are both .NET assemblies, using obsolete and ugly COM technology makes no sense at all. You have .NET, a decent OOP platform, while COM was created to bring OOP and interoperability to the word of non-OOP APIs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900