Click here to Skip to main content
15,887,746 members
Articles / Desktop Programming / Win32
Tip/Trick

Invoking foreign remoting interfaces in remote hosts using C#

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
22 Jun 2011CPOL1 min read 9.2K   2  
How to invoke foreign remoting interfaces in remote hosts.

I recently had to connect to an unmanaged COM Remoting service on a remote system, using C# and VS 2010. It turned out to be quite a hazzle, so hoping to save someone's day, here is how it's done.


The COM interface I needed was exposed by a .exe file called ovpmad.exe - the vendor did not provide any files to ease the process, so that was all that I had.


The first step is to extract the interface definition, which is stored in a .IDL file. There are numerous utilities for doing this, I used OleView.Exe from the Windows SDK.


The resulting .IDL file needs to be compiled into a .TLB file, which can be imported into a VS .NET project - another tool from the Win SDK "midl.exe" can be used to do this; in my case, a lot of forward declarations were missing in the IDL file, which I had to fix manually to get through the MIDL compilation.


Having the TLB file is the key, it can be added as a reference to the project, and it can be used to register the remoting interface on the client. The SDK utility "regtlibv12.exe" can be used for the registration, setting up all the Registry entries needed.


Finally, the interface can be invoked, as illustrated in the following example:


C#
Type theType = Type.GetTypeFromProgID("pmad.OvPmdPolicyManager.1", remoteHostName);
Object obj = Activator.CreateInstance(theType);

pmad = (OVPMADLib.IOvPmdPolicyManager) obj;

System.Array RootGroups = pmad.GetTopGroupList();
for (int i = 0; i < RootGroups.GetUpperBound(0); i++)
{
  IOvPmdPolicyGroup group = (IOvPmdPolicyGroup)RootGroups.GetValue(i);
  Console.WriteLine(group.GetName());
}

In this example, the variable remoteHostName is the server address, and pmad.OvPmdPolicyManager.1 is the name of the remoting interface.


If needed, the Windows utility dcomcnfg can be used to configure rights on the DCOM server.

License

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


Written By
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --