MFC extension dll
-
// dllmain.cpp : Defines the initialization routines for the DLL.
static AFX_EXTENSION_MODULE CLibCyMetaTraderDLL = { false, nullptr };
extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);
if (dwReason == DLL_PROCESS_ATTACH)
{
// Extension DLL one-time initialization
if (!AfxInitExtensionModule(CLibCyMetaTraderDLL, hInstance))
return 0;
// Insert this DLL into the resource chain
new CDynLinkLibrary(CLibCyMetaTraderDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
// Terminate the library before destructors are called
AfxTermExtensionModule(CLibCyMetaTraderDLL);
}
return 1; // ok
}
Dllmain 함수 인자 dwReason
- DLL 활용하는 프로세스에서 Dllmain 호출하는 상황에 따라 아래 4가지의 값이 전달됨.
DLL_PROCESS_ATTACH : DLL 사용 프로세스 생성(메모리에 DLL 로딩)시.
DLL_PROCESS_DETACH : DLL 사용 프로세스 종료(메모리에서 DLL 해제)시
DLL_THREAD_ATTACH : DLL 사용 프로세스의 새로운 스레드에서 DLL 로딩시.
DLL_THREAD_DETACH : DLL 사용 프로세스의 새로운 스레드에서 DLL 해제시.
new CDynLinkLibrary(CLibCyMetaTraderDLL);
- 리소스 체인에 확장 DLL 을 추가하는것.
- 확장 DLL 을 MFC regular dll 에서 로딩 시 주의사항.
- - 확장 DLL이 자체 리소스(대화상자, bmp등 모든 리소스) 기반 구현된것을 MFC regular dll 에서 로딩하려는 경우 확장DLL 에서 자신의 리소스에 접근 못하고 MFC gegular dll 의 리소스가 표현되는 원인이 되므로 필수 주의사항.
처리 요점.
- new CDynLinkLibrary(CLibCyMetaTraderDLL); 를 Dllmain 에서는 주석처리하고, 외부 노출함수 별도 마련하여 MFC regular dll 에서 해당 노출함수를 호출하여 명시적으로 실행시킬것.
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.
연관
첫 등록 : 2020.10.04
최종 수정 :
단축 주소 : https://igotit.tistory.com/
'VisualStudio.C++.C# > 코딩팁,함수활용,단편' 카테고리의 다른 글
std::queue. (0) | 2020.10.17 |
---|---|
std::vector. STL vector class. 사용법. (0) | 2020.10.14 |
MFC. CFileDialog . 파일열기, 쓰기 공통대화상자 (0) | 2020.10.02 |
MFC. 스크롤바 제거 (0) | 2020.10.02 |
MFC. CWnd::PreTranslateMessage . WM_KEYDOWN 핸들러로 수신못할 때. (0) | 2020.09.30 |
댓글