在ATL项目中使用第三方dll

Use third-party dll in ATL project

我有一个 C++ 非托管 dll。我没有这个 dll 的源代码,我需要在 ATL 项目中使用它

但是我总是报错"Retrieving the COM class factory for component with CLID {id} failed due to the following error: 80040154 class not registered"

我尝试使用 regsvr32 注册那个 dll,但没有成功 我已经阅读了很多教程,但它们都解释了如何从头开始创建 ATL 项目。而且他们不使用普通的dll

我该如何解决这个问题?

我以前的所有 ATL 项目都是 32 位的。一切正常。

这个项目是 64 位的。 我发现 Visual Studio 有一个错误: MSBuild ignores linker option "Register Output: Yes" for x64 Platform

解决方法 1(来自上面的 link):

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

解决方法 2(我在同一个解决方案中有 C# 项目,所以我使用了这个):

regsvr32 path_to_cpp.dll 添加到 post-构建事件

注意:你不应该将 regsvr32 添加到预构建中,因为它不会总是执行(另一个问题来源)

来自 MSDN:

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