Calling an old OLE component from C #

I have a very old (VC ++ 5.0) proprietary DLL that I need to use with C # (Visual Studio 2010). The example indicates that to access this component I need to call CreateDispatch("application")which points to OLE.

The following is sample code (C ++):

IComponentServer Server;
Server.CreateDispatch("Component.Server");

I added the link through Visual Studio to the TLB file that I have, and I can successfully import its namespace, but IComponentServerhas no method called CreateDispatch.

What is the right approach to instantiate an OLE component through C #?

+3
source share
2 answers

If you have a CLSID or ProgID, you can use the following set of methods.

var type = Type.GetTypeFromProgID(progIdString);
var obj = Activator.CreateInstance(type);
var server = (IComponentServer)obj;
+3

MFC CreateDispatch COM- CLSID ProgId. COM #.

, Visual Studio Interop.Component.dll:

IComponentServer server = new Interop.Component.ServerClass();
+1

Source: https://habr.com/ru/post/1761147/


All Articles