I wrote a simple Windows Service in C#, installed it and have it run as System.
I want to instantiate a COM object from the Microsoft Office Communicator Automation API:
using System.Collections.Generic
;
using System.Text;
using CommunicatorAPI;
using System.Runtime.InteropServ
ices;
namespace MyService
{
class OCSIntegrationUtil
{
private static Messenger _messenger;
public static void Register()
{
_messenger = new Messenger();
_messenger.OnContactStatus
Change += new DMessengerEvents_OnContact
StatusChan
geEventHan
dler(_mess
enger_OnCo
ntactStatu
sChange);
_messenger.OnMyStatusChang
e += new DMessengerEvents_OnMyStatu
sChangeEve
ntHandler(
_messenger
_OnMyStatu
sChange);
IMessengerContactAdvanced localUser = (IMessengerContactAdvanced
)_messenge
r.GetConta
ct(_messen
ger.MySign
inName, _messenger.MyServiceId);
System.Runtime.InteropServ
ices.Marsh
al.Release
ComObject(
_messenger
);
_messenger = null;
System.Runtime.InteropServ
ices.Marsh
al.Release
ComObject(
localUser)
;
localUser = null;
}
static void _messenger_OnMyStatusChang
e(int hr, MISTATUS mMyStatus)
{
// Your code to work with presence goes here...
Console.WriteLine("\n***On
MyStatusCh
ange***");
}
static void _messenger_OnContactStatus
Change(obj
ect pMContact, MISTATUS mStatus)
{
// Your code to work with presence goes here...
Console.WriteLine("\n***On
ContactSta
tusChange*
**");
}
}
}
However, when the service starts, it generates an Error in Event Log:
Retrieving the COM class factory for component with CLSID {8885370D-B33E-44B7-875D-2
8E403CF927
0} failed due to the following error: 80080005.
at MyService.OCSIntegrationUt
il.Registe
r()
at MyService.Service.Start()
I am successfully executing the preceding source code when I execute it in the context of a Console Application (i.e. I get OnMyStatusChange and OnContactStatusChange written at the screen whenever I change my status).
I'm familiar with programming, but not much with Windows Service programming. Anyone has a clue of why I get this error? Is it possible at all to do this in a service, or I am losing my time?