Creating a Communicator Object in C#

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.

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


Creating a Communicator Object in C/C++

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.

Copy Code
#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.

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

See Also