注册 DirectshowFilter 将 InprocServer32 注册表项链接到 regsvr32.exe 而不是主机 DLL,我哪里出错了?

Registering a DirectshowFilter links InprocServer32 registry entry to regsvr32.exe instead of host DLL, where did I go wrong?

我有一个 DirectShow 过滤器(MonogramAAC 编码器)编译成功。它也注册成功,但是,当我尝试在 GrapheditPlus 中实例化过滤器时,它显示 CO_E_ERRORINDLL。检查 GraphEditPlus 下的过滤器属性后,过滤器实际上链接到 RegSvr32.exe 而不是实际的主机 DLL!

证据如下:

我确定链接器中的 .def 文件是正确的,我还测试了编译器正在考虑它并且它正确指向过滤器 DLL。

一点面包背景信息:

原工程自动转换后无法在Visual Studio2017下编译。 (我无法解决 Monogram 过滤器和 libaac.lib 库之间奇怪的 MFC 和运行时库链接器错误,但我也能够成功编译).

最后我决定重新创建一个全新的 VS2017 项目来模仿原来的项目并让它编译和注册(唯一的警告是项目名称和输出库不匹配),但显然我错过了一些东西重新创建项目时很重要。

有指点吗?

好的,我设法找到了这种意外行为的原因 in this old post

RegSvr32 just calls the DllRegisterServer entry point in your code. What gets written to the registry is entirely up to your filter. If you are using the standard baseclass call to AMovieDllRegisterServer2 as your DllRegisterServer, I would suspect that something went wrong in setting up g_hInst, which should have been done by the call DllEntryPoint in your DllMain.

The DllMain is not being called, so g_hInst stays 0 and GetModuleFileNameA(...) returns the name of the currently executing program instead of my filter.

过滤器正在使用 MFC(动态链接),其 DllMain() 版本未调用 DllEntryPoint() 函数。我必须按照 an answer to this question 中的描述添加 extern "C" { int _afxForceUSRDLL; } 来覆盖 MFC DllMain() 并自己调用 DllEntryPoint() 来解决注册问题。 (我还发现缺少 #define 是 属性 页面未显示的原因)。