Search code examples
visual-c++comatl

Use third-party dll in ATL project


I have got a C++ unmanaged dll. I have no sources of this dll and I need to use it in ATL project

But I always get an error "Retrieving the COM class factory for component with CLID {id} failed due to the following error: 80040154 class not registered"

I have tried to register that dll using regsvr32, but no success I have read lots of tutorial, but all they explain how to created ATL project from scratch. And they do not use ordinary dlls

How can I solve this?


Solution

  • All my previous ATL project were 32-bit. And everything was working fine.

    This project was 64-bit. I've found out that Visual Studio has a bug: MSBuild ignores linker option "Register Output: Yes" for x64 Platform

    Workaround 1 (from the link above):

    <Target Name="RegisterOutput"
             Condition="'$(EmbedManifest)'=='true' and '$(LinkSkippedExecution)' != 'true' and (('$(Platform)' == 'x64' and ('$(PROCESSOR_ARCHITECTURE)' == 'AMD64' or '$(PROCESSOR_ARCHITEW6432)' == 'AMD64')) or '$(Platform)' == 'Win32')">
    

    Workaround 2 (I had C# project in the same solution, so I've used this one):

    Add regsvr32 path_to_cpp.dll to post-build event

    Note: you should not add regsvr32 to pre-build as it will not always execute (another source of problems)

    From MSDN:

    Pre-build events do not run if the project is up to date and no build is triggered.