DirectShow AMCap改装, 无法解析的外部符号 "class CFactoryTemplate * g_Templates"

qq_35084700 2017-05-02 10:33:08
错误 1 error LNK2001: 无法解析的外部符号 "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)
错误 2 error LNK2001: 无法解析的外部符号 "int g_cTemplates" (?g_cTemplates@@3HA)


1>strmbase.lib(dllentry.obj) : error LNK2001: 无法解析的外部符号 "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A)
1>strmbase.lib(dllentry.obj) : error LNK2001: 无法解析的外部符号 "int g_cTemplates" (?g_cTemplates@@3HA)

把AMCap代码文件复制到MFC工程里面,出现上述两个错误:STRMBASE.lib已经链接,不知道问题出在哪。
dllentry.cpp里面与上面相关的代码是:

extern CFactoryTemplate g_Templates[1];
extern int g_cTemplates;

//called by COM to get the class factory object for a given class
STDAPI
DllGetClassObject(
REFCLSID rClsID,
REFIID riid,
void **pv)
{
if (!(riid == IID_IUnknown) && !(riid == IID_IClassFactory)) {
return E_NOINTERFACE;
}

// traverse the array of templates looking for one with this
// class id
for (int i = 0; i < g_cTemplates; i++) {
const CFactoryTemplate * pT = &g_Templates[i];
if (pT->IsClassID(rClsID)) {

// found a template - make a class factory based on this
// template

*pv = (LPVOID) (LPUNKNOWN) new CClassFactory(pT);
if (*pv == NULL) {
return E_OUTOFMEMORY;
}
((LPUNKNOWN)*pv)->AddRef();
return NOERROR;
}
}
return CLASS_E_CLASSNOTAVAILABLE;
}

//
// Call any initialization routines
//
void
DllInitClasses(BOOL bLoading)
{
int i;

// traverse the array of templates calling the init routine
// if they have one
for (i = 0; i < g_cTemplates; i++) {
const CFactoryTemplate * pT = &g_Templates[i];
if (pT->m_lpfnInit != NULL) {
(*pT->m_lpfnInit)(bLoading, pT->m_ClsID);
}
}

}
...全文
586 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
oyljerry 2017-05-03
  • 打赏
  • 举报
回复
g_Templates这个要有地方在别的cpp中定义全局变量
zgl7903 2017-05-03
  • 打赏
  • 举报
回复
extern CFactoryTemplate g_Templates[1]; 实例在哪里? 需要 CFactoryTemplate g_Templates[1];
qq_35084700 2017-05-03
  • 打赏
  • 举报
回复
#ifdef FILTER_DLL /* List of class IDs and creator functions for the class factory. This provides the link between the OLE entry point in the DLL and an object being created. The class factory will call the static CreateInstance function when it is asked to create a CLSID_SystemClock object */ CFactoryTemplate g_Templates[1] = { //{&CLSID_SystemClock, CSystemClock::CreateInstance} { L"SystemClock", &CLSID_SystemClock, CSystemClock::CreateInstance} }; int g_cTemplates = sizeof(g_Templates) / sizeof(g_Templates[0]); #endif 找到问题了,楼上两位都说得对,表面上看是STRMBASE.lib的问题,而STRMBASE.lib是编译自BaseClasses。上面的代码是关键,截取自BaseClasses项目的sysclock.cpp,FILTER_DLL没有预定义,所以出现问题,添加预定义就好了。

3,248

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧