This documentation is archived and is not being maintained.

Object Instantiation

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

In C#, the System.Runtime.Interop namespace enables a COM object to be created in a C# class wrapper. This is illustrated in the following C# code snippet.

using System;
using System.Runtime.Interop;
using CommunicatorAPI;
class MyClass
   CommunicatorAPI.Messenger communicator= null;
   public MyClass()
     communicator = new CommunicatorAPI.Messenger();


The following code snippet illustrates how to create the Messenger object and, thus, to obtain the interface pointer to the IMessenger interface, by calling the CoCreateInstance function of the COM library. It is assumed that the required msgrua.h file is already installed in the c:\program files\Microsoft Office Communicator\SDK directory, the default installation directory of the Communicator SDK.

#define WINVER 0x0500
#define _WIN32_WINNT 0x0500

#pragma once

#include <windows.h>
#include <tchar.h>
#include "c:\program files\Microsoft Office Communicator\SDK\msgrua.h"

IMessenger* m_pIMessenger;

int _tmain(int argc, _TCHAR* argv[])

   // Create Messenger object, retrieve IMessenger interface pointer 
   // and connect to the running Communicator instance.
   hr = CoCreateInstance(CLSID_Messenger,NULL,CLSCTX_LOCAL_SERVER,
            IID_IMessenger, (LPVOID *)&m_pIMessenger);

   if (FAILED(hr))
      return hr;

   // The IMessenger interface is now ready for use. For example,
   BSTR myName;
   hr = m_pIMessenger->get_MyFriendlyName(&myName);

   BSTR serviceId;
   hr = m_pIMessenger->get_MyServiceId(&serviceId);


   return 0;

Creating a Communicator Object in JavaScript

The following JavaScript code snippet illustrates how to create a Messenger object using Office Communicator Automation API.

var comm = new ActiveXObject("Communicator.UIAutomation");