프로그래밍/VC++

MFC OCX에 strmbasd.lib를 넣으면 error LNK2001: "class CFactoryTemplate * g_Templates 에러나는 경우 해결

panpro 2007. 3. 27. 17:15
MFC AcitveX에 strmbasd를 추가하고 컴파일하는 순간 Dialog Based에서는 잘 되던게 바로 아래와 같은 6개의 빌드오류를 내버린다.

  • axLiveSourceRecorder error LNK2001: "class CFactoryTemplate * g_Templates" (?g_Templates@@3PAVCFactoryTemplate@@A) 외부 기호를 확인할 수 없습니다.
  • axLiveSourceRecorder error LNK2001: "int g_cTemplates" (?g_cTemplates@@3HA) 외부 기호를 확인할 수 없습니다.
  • axLiveSourceRecorder error LNK2019: __imp__timeGetTime@0 외부 기호("void __stdcall DbgInitialise(struct HINSTANCE__ *)" (?DbgInitialise@@YGXPAUHINSTANCE__@@@Z) 함수에서 참조)를 확인하지 못했습니다.
  • axLiveSourceRecorder error LNK2001: __imp__timeGetTime@0 외부 기호를 확인할 수 없습니다.
  • axLiveSourceRecorder error LNK2019: __imp__timeSetEvent@20 외부 기호("unsigned int __stdcall CompatibleTimeSetEvent(unsigned int,unsigned int,void (__stdcall*)(unsigned int,unsigned int,unsigned long,unsigned long,unsigned long),unsigned long,unsigned int)" (?CompatibleTimeSetEvent@@YGIIIP6GXIIKKK@ZKI@Z) 함수에서 참조)를 확인하지 못했습니다.
  • axLiveSourceRecorder fatal error LNK1120: 4개의 확인할 수 없는 외부 참조입니다.


그 해결방법은 다음과 같다.
출처 : http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=868592&SiteID=1

hi again!
I was completly wrong!
this code bellow is te solution:

/////////////////////////////////////////////////////////////////////////////
// DllGetClassObject

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

Why is that?hehe. I think that it is because when you import strmbase.lib (or strmbasd.lib for debug) to an activex project, it takes firstly the definition of the "DllGetClassObject" from strmbase.lib as the dll entry point or something like that. when you redefine "DllGetClassObject" in your code, it takes the correct pointer of the activex. The question is:
Why does microsoft not explain this commonly used topic on its directshow FAQ questions?

I hope this helps someone else.....regards,
villalvilla.

ps:the prj0019 error was solved including the filter's generated file in the activex's release folder.


결론은 ctrl.cpp 파일 맨끝에

/////////////////////////////////////////////////////////////////////////////
// DllGetClassObject

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

만 추가해주면 된다.