Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dcom in c#

Status
Not open for further replies.

tomcoombs

Programmer
Aug 14, 2003
65
GB
I used to be a c++ programmer using dcom to make portable code that runs over networks.

I want to interface to a C++ program from c#.

Is this possible, c# seems to harp on about "remoting" all the time, which I assume can no be used in c++.



Any ideas?

Thanks

Tom
 
Yes, this is easy. You can use "TLBIMP" to generate a wrapper assembly from the TLB file describing your DCOM server. After that, accessing the DCOM server is as easy as accessing any other .Net assembly.
 
Thanks for the answer, my solution at the time was to simply :

Type tServerType;

// Retrieve the type information
tServerType = Type.GetTypeFromProgID("GeevsSwitcherServer.SwitcherSvr", m_strServerName);

// Create an instance of the remote server object locally.
object obj = null;

try
{
obj = Activator.CreateInstance(tServerType);
}
catch(Exception exc)
{
string strErr;
strErr = "Failed to connect.\n" + exc.Message;
MessageBox.Show(strErr, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Stop);
return;

}

try
{
m_Switcher = (ISwitcherSvr) obj;
}


Why did I not need to use your method?


Kind Regards


Tom
 
The difference is early binding vs. late binding.

Running tblimp gives you a wrapper class that you can reference, thus doing early binding. A hazard is that the other class may change it's CLSID (VB6 projects without binary-compatibility being set are notorious for doing this).

Using the System.Activator class means you're doing late-binding. It's slower, but protects you against changes in the CLSID.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
You must have done a little more than you show.

For this line to work
m_Switcher = (ISwitcherSvr) obj;

you had to define "ISwitcherSvr" somewhere. If you had been doing complete late binding, you would have been using "Invoke" methods with named methods, instead of calling through an interface.

If you manually defined ISwitcherSvr, and if that interface is defined in your TLB, you could have relied on the automatically defined interface in your wrapper instead of redefining it in C#.

You may have generated the wrapper without realizaing it from within the IDE, by adding a reference to an item on the COM tab of the "add reference" dialog box. The wrapper generated that way is the same as the wrapper generated from the command line via TLBIMP. In that case, the wrapper would be in the "object" folder of your project.
 
Yeah - I did "add reference" so it looks like I was using a wrapper.


Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top