How to use COM object in .Net Code
There has been a lot of investment in COM/MTS/COM+/Win32 DLLs, and it will not be feasible to migrate that entire code base to .NET. But you don't have to worry about it because you can access your legacy code from .NET code and vice versa.
The steps:
1. Create a "Wrapper DLL" by doing: tlbimp OriginalCOM.dll OriginalCOM_net_wrapper.dll
2. Compile your code which uses this COMObject (sample below) by using the following switch:
csc /reference:OriginalCOM_net_wrapper.dll /out:ManagedClient.exe ManagedClient.cs
3. Sample Source code of ManagedClient.cs:
1 using System;
2 using OriginalCOM;
3
4 class ManagedClient
5 {
6 public static void Main()
7 {
8 CTest objTest ;
9 objTest = new CTest() ;
10 string strMessage = "15Seconds reader" ;
11 strMessage = objTest.SayHello(strMessage) ;
12 Console.WriteLine(strMessage) ;
13 Console.WriteLine("\nPress any key to exit") ;
14 Console.Read() ;
15 }
16 }
For complete details, please go to:
http://www.15seconds.com/Issue/010129.htm

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home