Thursday, August 15, 2013

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 = "some_m...@gmail.com"
myMail.Subject = "Sending mail from MS Outlook using QTP"
myMail.Body= "Test Mail Contents"

'Send the mail
myMail.Send

2 comments:

  1. Thank you soo much....very nice explanation

    ReplyDelete
  2. Hi,
    Great information about Component Object Model. Can you explain about What are the advantages and disadvantages of TestComplete over QTP?
    Thanks,
    David,
    QTP Developer

    ReplyDelete