You are on page 1of 3

Component Object Model( COM )

COM or 'Component Object Model'

COM or 'Component Object Model' is a method by which an application exposes its
functionalities to other applications & programming languages using a set of methods
and functions.

As an example consider Microsoft Outlook Application. You can open Outlook and then
send mails, manage appointments & do many other things. Now what if you want to do
all these tasks through code ( i.e. without manually opening Outlook). This is the
situation where you would need COM.

Microsoft Outlook exposes all its functionalities in form of certain methods and
properties. You can access these methods using any programming language like C#, VBA,
VBScript etc and directly interact with MS Outlook.

Check out the below code to send mail using MS Outlook.

'Create an object of type Outlook
Set objOutlook = CreateObject("Outlook.Application")
Set myMail = objOutlook.CreateItem(0)

'Set the email properties

myMail.To = ""
myMail.Subject = "Sending mail from MS Outlook using QTP"
myMail.Body= "Test Mail Contents"

'Send the mail

COM objects are discrete components, each with a unique identity, which expose interfaces that allow
applications and other components to access their features. Microsoft COM (Component Object Model)
technology in the Microsoft Windows-family of Operating Systems enables software components to
COM is used by developers to create re-usable software components, link components together to build applications, and take
advantage of Windows services.

For example,There will be Copy,Paste functionality used in Excel,word,ppt etc.,

Therefore,instead of writing code separately for Copy,Paste functionality in Excel,word,ppt etc.,they will create
reusable copy,paste component and call it from Excel,word,ppt etc.,This increases code reusability.
Distributed Component Object Model(DCOM)

Distributed Component Object Model is an extension of the Component Object Model (COM) that allows COM
components to communicate across network boundaries.
Traditional COM components can only perform interprocess communication across process boundaries on the same machine. DCOM
uses the RPC mechanism to transparently send and receive information between COM components (i.e., clients and servers) on the
same network.
Remote procedure call (RPC) is an inter-process communication that allows a computer program to cause a subroutine or procedure
to execute in another address space (commonly on another computer on a shared network) without the programmer explicitly coding
the details for this remote interaction.
There are Object models for Excel,word,power point,File system object and Dictionary object and so on.

Let us consider Excel and File system objects for examples

n Excel Object Model

To develop solutions that use Microsoft Office Excel, you can interact with the objects provided by the Excel
object model.Using Excel object,we can interact with Workbooks,worksheets,cells in excel sheet through
Below code snippet illustrates the Creation excel file,entering some data and saving it
'Create Excel Object
Set excel=createobject("excel.application")
'Make it Visible
'Add New Workbook
Set workbooks=excel.Workbooks.Add()
'Set the value in First row first column
excel.Cells(1,1).value=" "
'Save Work Book
'Close Work Book
'Quit from Excel Application
'Release Variables
Set workbooks=Nothing
Set excel=Nothing
n File System Object:
When writing scripts, it's often important to add, move, change, create, or delete folders (directories) and files
on the Web server.
It may also be necessary to get information about and manipulate drives attached to the Web server.Scripting allows you to process
drives, folders, and files using the FileSystemObject (FSO) object model
Below code snippet creates text file,enters some text and saves it
' Declare variables
Dim fso, MyFile
To use a COM object in a script, you must first create an instance of the object. You can do this by calling the CreateObject
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("c:\ Automation365.txt", True)
MyFile.WriteLine("we are from Automation365 ")
Set fso = Nothing