Step 1: Create a wrapper done at runtime. There are two ways:
Method 1: use TlbImp to generate RCW
tlbimp <YourCOMSvr>.tlb /out:<YourCOMSvr>.dll
using this method, the standard .NET-Interop Marshalling is used (sometimes when it does not work) you need to change the marshalling by following the additional steps
ildasm <YourCOMSvr>.dll /out:<YourCOMSvr>.il //Modify <YourCOMSvr>.il ilasm <YourCOMSvr>.il /dll
Method 2. Manually creating a C ++ / Cli project serves as a wrapper for the COM server.
Step 2: C # Code
Link to RCW and use the following code to connect to the COM server
Type yourComType= Type.GetTypeFromProgID(yourComSvrProgID, serverPcName); var oInterface = (IYourCOMInterface)Activator.CreateInstance(yourComType);
source share