How to initialize the CLR in an ATL ActiveX DLL

I have an ATL C++ project for an ActiveX component that needs to call managed code in Visual Studio 2005.

The reason that this project must be an ATL ActiveX DLL is that it is a plug-in to another program that embeds its plug-ins by creating specified ActiveX components. The host program is not built using .NET, so it does not initialize the CLR by itself.

I followed the instructions in the help docs, so now the project is mostly compiled using /clr, which, I understand, enables the intrinsic CLR features of the Visual C++ language.

Does this switch also automatically include initialization of the CLR when the DLL is loaded, or do I have to call CorBindToRuntimeEx() also

I tried including mscoree.h, and compiling the project with the call to CorBindToRuntimeEx() function, but I get the following build error:

Error 1 fatal error C1083: Cannot open include file: 'product_version.h': No such file or directory C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\include\mscoree.idl 19



Answer this question

How to initialize the CLR in an ATL ActiveX DLL

  • Michal Januszczyk

    Hi Staffan,

    It's actually quite simple. In any file/project where you throw the /clr switch, you can now access .NET as easily as you would in C#. In this case, you do not need to call CorBindToRuntimeEx() or include mscoree.h. You can start using classes from the BCL by typing in System:: (and check out the ensuing Intellisense).



  • How to initialize the CLR in an ATL ActiveX DLL