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);
}
}

}
...全文
534 3 打赏 收藏 转发到动态 举报
写回复
用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没有预定义,所以出现问题,添加预定义就好了。
amcap源代码,visual studio 亲测通过,打开摄像头设备。 // File: AMCap.h // // Desc: DirectShow sample code - audio/video capture. // // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Macros #define SAFE_RELEASE(x) { if (x) x->Release(); x = NULL; } // device notification definitions #if (WINVER < 0x0500) #define DBT_DEVTYP_DEVICEINTERFACE 0x00000005 // device interface class #define DEVICE_NOTIFY_WINDOW_HANDLE 0x00000000 typedef PVOID HDEVNOTIFY; #endif extern "C" { typedef BOOL (/* WINUSERAPI */ WINAPI *PUnregisterDeviceNotification)( IN HDEVNOTIFY Handle ); typedef HDEVNOTIFY (/* WINUSERAPI */ WINAPI *PRegisterDeviceNotificationA)( IN HANDLE hRecipient, IN LPVOID NotificationFilter, IN DWORD Flags ); typedef HDEVNOTIFY (/* WINUSERAPI */ WINAPI *PRegisterDeviceNotificationW)( IN HANDLE hRecipient, IN LPVOID NotificationFilter, IN DWORD Flags ); } #ifdef UNICODE #define PRegisterDeviceNotification PRegisterDeviceNotificationW #else #define PRegisterDeviceNotification PRegisterDeviceNotificationA #endif // !UNICODE #if (WINVER < 0x0500) typedef struct _DEV_BROADCAST_DEVICEINTERFACE_A { DWORD dbcc_size; DWORD dbcc_devicetype; DWORD dbcc_reserved; GUID dbcc_classguid; char dbcc_name[1]; } DEV_BROADCAST_DEVICEINTERFACE_A, *PDEV_BROADCAST_DEVICEINTERFACE_A; typedef struct _DEV_BROADCAST_DEVICEINTERFACE_W { DWORD dbcc_size; DWORD dbcc_devicetype; DWORD dbcc_reserved; GUID dbcc_classguid; wchar_t dbcc_name[1]; } DEV_BROADCAST_DEVICEINTERFACE_W, *PDEV_BROADCAST_DEVICEINTERFACE_W; #ifdef UNICODE typedef DEV_BROADCAST_DEVICEINTERFACE_W DEV_BROADCAST_DEVICEINTERFACE; typedef PDEV_BROADCAST_DEVICEINTERFACE_W PDEV_BROADCAST_DEVICEINTERFACE; #else typedef DEV_BROADCAST_DEVICEINTERFACE_A DEV_BROADCAST_DEVICEINTERFACE; typedef PDEV_BROADCAST_DEVICEINTERFACE_A PDEV_BROADCAST_DEVICEINTERFACE; #endif // UNICODE #endif // WINVER

3,245

社区成员

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

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