Com Interop Tutorial
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront
Chapter:   UnCategorized
Current Lesson:
Com Interop Tutorial
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Introduction to Serialization [next Lesson]  Regular Expression
Com Interop Tutorial
  by: Gsuttie

Com Interop Tutorial



by: Gsuttie

The following is an example of some Com Interop to legacy MTS Components which are housed on a seperate server.

Lets say for example that the Component we want to use is called MyComponent. MyComponent.dll sits on server B and we have to DCOM to this due to the fact that we have been provided with MyComponent.tlb and MyComponent.dll (we dont get want to register the dll on the box as this would defeat the purpose).

Firstly we need to get the tlb and vbr pointing from our box Server A to MyComponent on Server B.

Lets assume we dont have any security or privileges problems as thats outwoth the scope of the tutorial.

Copy the tlb and vbr to the winnt\system32 folder on your machine.

Open a command prompt and type the following:
c:>cd winnt\system32 <enter>
You should now have:
c:>cd winnt\system32 <enter>
Now assuming you have clireg on your machine type
clireg32 MyComponent.vbr -t MyComponent.vbr <enter>
When the dialog box appears choose a Protocol (ncacn_ip_tcp), a Remote Transport (Remote Automation), and a Network Address (Server B).

Then type the above line again - clireg32 MyComponent.vbr -t MyComponent.vbr <enter> but this time change the Remote Transport to DCOM with the same Networek Address (Server B).

At this point we should be setup to DCOM to Mycomponent to DLL - you may want to test this with a simple vb6 test form.

Back in Visual Studio.net within our project we want to add a reference to our project to the MyComponent.tlb. To do this go to the Project menu and select Add Reference. Choose the Com tab and browse for MyComponent.tlb and add it. This will add a reference to the tlb which means were ready to start coding.

Within your csharp page we need to add a reference to the code in MyComponent. At this point we even have intellisens which is very handy indeed.
MyComponent.MethodName obj = new MyComponent.MethodNameClass();
The line above means we noe have a Mycomponent Object and we can call the code and if you have MTS you can watch the object in call and being activated. In order to release the com object from memory we can do this below:
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
Once again we can watch the object being released in MTS.

If you should come across some problems with the above code then feel free to contact me at gsuttie@aol.com.

Thanks

Gregor


1 


Build Your Own ASP.NET Website Using C# & VB.NET

Chapter:  UnCategorized
Current Lesson:
Com Interop Tutorial
[Latest Content]
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | ALL
[prev. Lesson]  Introduction to Serialization [next Lesson]  Regular Expression


Today's Top Movers
vulpes 6800
MadHatter 2220
jal 867
Jeff1203 857
muster 791

Yesterday Top Movers
shakti sin.. 9
MadHatter 3
C#fanatic 2
Al_Pennywo.. 2
GazzaJ 1

Monthly Leaders
vulpes 6800
MadHatter 2260
jal 867
Jeff1203 857
muster 791

Top Members
mosessaur 18457
Rincewind 7074
stanleytan 6995
vulpes 6800
Gsuttie 6046

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
zonealarm
spam blocker
web hosting directory
ad server   C#
snadtech GoToMyPc

Top of Page

Advertise | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center