This post contains attachments v20021022220011.zip 
Summary
This article explores the interaction of COM components like Microsoft Word application with .Net Framework.
In this article, I am going to explore how we can interact with COM components like Microsoft Word application. I will explain this concept with a program which was written in both VB.Net and C#.Net. This program basically counts the number of characters in your document and displays all those characters in your console window. This gives you an idea on how COM components can interact with .Net framework.
First you need to create the Interop Assembly using Type Library Importer (Tlbimp.exe), which is a tool that converts COM type library coclasses and interfaces into metadata.
To execute this article on your machine, Microsoft Word should be installed. If installed, find the path of MsWord9.olb file. In Ideal cases the path will be C:\Program Files\Microsoft Office\Office. Then create the interop assembly from the type library, using the following command.
C:\pandu\asp\Word>Tlbimp C:\Program Files\Microsoft Office\Office\ MsWord9.olb /silent /out:Word.dll
Here the second argument /silent suppress the display of successful messages.
This command instruction creates a metadata, which is the Interop assembly.
Create a word document by saving it as WordTest.doc in C: drive. You can save this file anywhere but you need to give the path of this file in your code.
Then write the following programs, which uses the created Interop Assembly:
Compile it as follows:
C:\pandu\asp\Word>csc wordConvert.cs /r:Word.dll /r:System.dll
Note that Word.dll and wordConvert.cs should be in the same folder.
Compile it as follows:
C:\pandu\asp\Word>vbc wordConvert.vb /r:Word.dll /r:System.dll
Note that Word.dll and wordConvert.cs should be in the same folder.
Here you can notice the coding differences between the two languages and their syntax.
System Requirements:
.Net SDK
|