본문 바로가기
VisualStudio.C++.C#/코딩팁,함수활용,단편

MFC. Extension DLL. 확장 DLL

by i.got.it 2020. 10. 4.

 

 

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.

 

 

 

연관 

 

 

MFC Extension DLL 만들기. ChartDirectorViewer

개요 Visual Studio 2015 MFC extension dll 만들기. 본 글에서 예로 사용되는 "확장DLL 프로젝트" 이름 : ChartDirectorViewer 기능 : Chart Director for C++( http://igotit.tistory.com/553 ) 에서 제공하는..

igotit.tistory.com

 


첫 등록 : 2020.10.04

최종 수정 : 

단축 주소 : https://igotit.tistory.com/

 


 

댓글



 

비트코인




암호화폐       외환/나스닥/골드       암호화폐/외환/나스닥/골드 암호화폐/외환/나스닥/골드   암호화폐/외환/나스닥/골드
     
현물 |선물 인버스 |선물 USDT       전략매니저(카피트레이딩)     롤오버 이자 없는 스왑프리계좌
( 스왑프리 암호화폐도 거래 가능 )    
MT4, MT5 , cTrader 모두 지원     FTMO 계좌 매매운용. MT4,MT5