Strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)
Strmbasd.lib(dllentry.obj) : error LNK2001: unresolved external symbol "int g_cTemplates" (?g_cTemplates@@3HA)
类似这样的链接错误。
goole了好久,发现构造g_Templates ,g_cTemplates两个变量能解决链接问题,但是不能解决运行问题。问题根源在于DllGetClassObject函数链接到了STRMBASE.lib 里的dllentry.cpp里的函数原型,而这个DllGetClassObject实现又引用了g_Templates ,g_cTemplates两个变量,因此出现上述链接错误。dllentry.cpp里的DllGetClassObject实现是用于directshow filter com dll的, 其实mfc 的activex 需要DllGetClassObject调用AfxDllGetClassObject。
因此加入如下代码:
extern "C"
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllGetClassObject(rclsid, riid, ppv);
}
/
// DllCanUnloadNow
extern "C"
STDAPI DllCanUnloadNow(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
return AfxDllCanUnloadNow();
}