본문 바로가기
VisualStudio.C++.C#

VC++, DLL 활용하는법.- implicit linking (암시적 연결방식)

by i.got.it 2019. 4. 16.

 

 

 

개요.

 

 

VC++ 프로젝트에서 DLL 활용하는법 정리. - implicit linking 방법.

 

VC++ 프로젝트에서 DLL 을 임포팅하는 방법은 크게 implicit linking 과 explicit linking 이 있다.

implicit linking 은 프로그램이 실행될때 로딩되어 프로그램 종료될 때 해제되는 반면 explicit linking은 프로그램 실행후 원하는 시점에 로딩과 해제가 가능하다는 점이 큰 차이다.



 

dll 위치

1. implicit linking  인 경우 dll 은 반드시 exe 와 동일 경로에 있어야 한다.

2. 상기 1이 아닌 경우는 윈도우 운영체제 기본 system32 폴더에 있든지,

3. 혹은 임의 폴더에 dll 을 배치하려면 운영체제의 PATH 설정해야한다.

dll 활용하는 실행프로그램 배포 간결함을 위해서는 상기 1처럼 exe와 동일 경로에 두는 것이 가장 무난하다.



MS사제공 DLL 경로 정보.


  1. The directory where the executable module for the current process is located.
  2. The current directory.

  3. The Windows system directory. The GetSystemDirectory function retrieves the path of this directory.

  4. The Windows directory. The GetWindowsDirectory function retrieves the path of this directory.

  5. The directories listed in the PATH environment variable.

from : https://msdn.microsoft.com/en-us/library/7d83bc18(v=vs.140).aspx





임의 시점 dll 로딩과 해제가 필수로 요구되는 경우를 제외하고는 implicit linking 을 이용하자.

 

implicit linking 을 위해서는 3개의 파일(*.DLL, *.h, *.lib)이 요구된다.

1. *.DLL (라이브러리의 실행되는 실체는 이것임.)

2. *.lib  (implicit linking 위해서 필요한 파일.)

3. *.h (상기 DLL 에서 제공하는 함수 선언 등이 있는 파일.)

4. DLL 활용 설명문.(함수사용법, 주의사항등의 DLL 제작사의 설명문.)

 

2,3,4는 1을 위해 있는것들이다.

 

본 글에서의 설명은 implicit linking 임.


참고.

explicit linking  방법 보기 :  http://igotit.tistory.com/1248

 

 

 

 

 

DLL 파일 배치.

 

 

*.lib 와 *.h 파일.

 

DLL 을 활용하는 VC++ 프로젝트의 소스파일 있는 곳에 .lib , .h 파일을 배치한다.

 

*.dll 파일.

 

VC++ 프로젝트의 실행파일이 있는 곳에 배치한다.

 

 

 

 

 

VC++ 프로젝트에서 dll 연결코드 추가.

 

 

VC++ 프로젝트의 소스코드(.cpp 파일) 의 상단에 아래 처럼 2줄 추가하면 설정은 끝. 

 

 

 

#pragma comment(lib,"dll이름.lib")  // DLL Implicit import

 

#include "dll이름.h"  // DLL의 함수선언, 사용되는 구조체 선언등이 있는 파일.

 

 

 

이제 DLL에서 제공하는 함수 호출등 DLL 활용 가능하다.

 

 

 



동영상. implicit linking  방법 상세.

- 상황예. CyFinAPI (MFC Regular DLL) 을 CyFinAPI_L:auncher (Dialog 기반 app) 에서 로딩하는 과정 . 

- 32bit, 64bit 예를 모두 보임. 



상기 링크 처리이후 Launcher 실행하여 DLL 제공함수 호출예. 






 본 글이 포함된 상위 정리 장소.

 

 Visual Studio/VC++/C/C# 활용정리 -> http://igotit.tistory.com/11

 




첫등록 : 2015년 12월 3일 

최종수정 : 2019년 4월 16일 


본 글 단축주소 : https://igotit.tistory.com/471





///471.

댓글



 

비트코인




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