How to use ATl COM from a windows service

419 views Asked by At

Using the VS2008 wizard, I have created a Service (That does nothing currently other than Start and Stop)

I wish to use an (out of process) COM object

If I add a #import "object.tlb", then recompilation gives

error C2812: #import is not supported with /clr:pure and /clr:safë

Changing properties to use /clr (not pure or safe), allows compilation, but install of the service fails with "Ättempt to load an unverifiable executable with fixups"

Any advice appreciated

Peter

1

There are 1 answers

0
Hans Passant On BEST ANSWER

It is explicitly mentioned in the MSDN article for InstallUtil.exe:

Note that you cannot deploy a Windows service created using C++ with Installutil.exe. Installutil.exe cannot recognize the embedded native code that is produced by the C++ compiler. If you attempt to deploy a C++ Windows service with Installutil.exe, an exception such as BadImageFormatException will be thrown. To work with this scenario, move the service code to a C++ module. Then, write the installer object in C# or Visual Basic.