Microsoft MVP성태의 닷넷 이야기
VC++: 11. Delay Loaded DLL [링크 복사], [링크+제목 복사],
조회: 28114
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 


DLL을 과연 언제 delay loaded 방식으로 처리하는 것이 좋을까요?

첫 번째 이유는, 당연히 최초 Application의 로딩 속도를 빠르게 하고 싶어서입니다. 이건 너무나 당연한 것이라서 더 이상 설명의 여지가 없지요.

두 번째 이유는, 다중 환경을 지원하기 위해서 delay loaded 방식을 사용할 수 있습니다. 음... 다중 환경이라... 예를 한번 들어볼까요?

TestMethod라는 Win32 API가 Windows XP 이상에만 포함된 Test.DLL 파일에만 구현되어 있다고 해봅시다. 그런 경우, Test.lib에 링크를 해버리면 해당 프로그램은 Windows 98에서는 실행조차 할 수가 없게 되지요. 만약 개발자가, Win98에서는 해당 기능을 사용하려고 할 때에 불가능하다는 메시지를 띄우게 하고, WinXP 이상인 경우에는 정상적으로 사용하도록 프로그램하고 싶다면!

바로 그럴 때, delay loaded 방식으로 Test.DLL과 링크를 시켜주면 됩니다. 다음과 같은 식이면 좋겠지요.

if (IsWin98() == true)
{
  MessageBox(NULL, "WinXP 이상에서만 사용할 수 있습니다.", NULL, MB_OK);
} else {
   TestMethod();
}

물론, GetProceAddress / LoadLibrary를 사용한 방법도 있는데, 그런 경우에는 호출이 delay loaded DLL 방식보다 더 복잡하게 되지요. 소스의 간결성 차원에서라도 바람직한 방법은 아닙니다.

자, 이제 그럼 어떻게 Delay Loaded 방식으로 링크할 수 있을까요?
경우의 수는 여러 가지가 있겠지만, 제가 주로 사용하는 틀은 다음과 같습니다.

VS.NET 2005의 경우.

: 소스
#pragma comment( lib, "Test.lib" )

: 프로젝트 속성
좌측 트리에서 Configuration Properties / Linker / Input을 선택하면 우측 리스트 박스에 Delay Loaded DLLs 항목이 나옵니다. 거기에 "Test.dll"이라고 추가해 주면 됩니다.

그리 어렵지 않지요. ^^ 사실, delay loaded 방식에 대해서 소개된 지는 오래되었지만. 이제서야 한번 실제 적용을 해보게 되는군요. ^^

이외에도 다음의 토픽을 함께 봐두시는 것도 좋을 것 같아서 링크를 적어봅니다.

Explicitly Unloading a Delay-Loaded DLL :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vcconexplicitlyunloadingdelay-loadeddll.asp

Loading All Imports for a Delay-Loaded DLL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vclrfLoadingAllImportsForDelayLoadedDLL.asp

Changes in the DLL Delayed Loading Helper Function Since Visual C++ 6.0 :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vccore/html/vchowChangesInHelperFunctionFromVisualC60.asp











[최초 등록일: ]
[최종 수정일: 6/26/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...
NoWriterDateCnt.TitleFile(s)
11091정성태11/3/201629059VC++: 104. std::call_once를 이용해 thread-safe한 Singleton 객체 생성파일 다운로드1
11090정성태11/1/201630629VC++: 103. C++ CreateTimerQueue, CreateTimerQueueTimer 예제 코드 [9]파일 다운로드1
11089정성태11/1/201631306디버깅 기술: 82. Windows 10을 위한 Symbol(PDB) 파일 내려받는 방법 [2]
11088정성태11/1/201633218.NET Framework: 617. C# - AForge.NET을 이용한 MP4 동영상 파일 재생 [7]파일 다운로드1
11087정성태11/1/201627542.NET Framework: 616. AForge.Video.FFMPEG를 최신 버전의 ffmpeg 파일로 의존성을 변경하는 방법파일 다운로드1
11086정성태11/1/201622318오류 유형: 366. The Microsoft Passport Container service terminated with the following error: General access denied error
11085정성태10/27/201637732.NET Framework: 615. C# - AForge.NET을 이용한 웹캠 영상 출력 [2]파일 다운로드1
11084정성태10/26/201625225오류 유형: 365. The User Profile Service service failed to the sign-in.
11083정성태10/26/201631746Windows: 131. 윈도우 10에서 사라진 "Adapters and Bindings" 네트워크 우선 순위 조정 기능 [1]
11082정성태10/26/201634748.NET Framework: 614. C# - DateTime.Ticks의 정밀도 [4]파일 다운로드1
11081정성태10/26/201624004오류 유형: 364. You need to fix your Microsoft Account for apps on your other devices to be able to launch apps and continue experiences on this device.
11080정성태10/24/201628251Windows: 130. Windows Server 2016 Nano 서버 설치 방법
11079정성태10/21/201625250Windows: 129. Windows Server 2016 설치 CD에 있는 Convert-WindowsImage.ps1 사용 방법 정리
11078정성태10/21/201626369Windows: 128. Windows Server 2016 Nano 서버 VHD 이미지 만드는 방법 - TP5 기준
11077정성태10/21/201623979오류 유형: 363. Active Directory 서버의 NETLOGON 서비스가 멈췄을 때 발생하는 문제
11076정성태10/21/201624333오류 유형: 362. 윈도우 백업 시 오류 - 0x80780040
11075정성태10/20/201624070Windows: 127. Convert-WindowsImage.ps1 사용 방법 정리
11074정성태10/20/201633578Windows: 126. Windows Server 2016 평가판을 정식 버전으로 라이선스 변경하는 방법
11073정성태10/20/201629911.NET Framework: 613. 윈도우 데스크톱 응용 프로그램(예: Console)에서 알림 메시지(Toast notifications) 띄우기 [1]파일 다운로드1
11072정성태10/20/201626783VC++: 102. 새로 추가한 ATL COM 객체가 regsvr32.exe로 등록이 안 되는 문제
11071정성태10/20/201629784.NET Framework: 612. UWP(유니버설 윈도우 플랫폼) 앱에서 콜백 함수 내에서의 UI 요소 접근 방법 [1]
11070정성태10/20/201622883Windows: 125. 윈도우 서버 2016 마이그레이션
11069정성태10/19/201631177.NET Framework: 611. C++ 개발자들을 위한 C# Thread 동작 방식 [2]
11068정성태10/19/201633948Windows: 124. 윈도우 운영체제의 시간 함수 (5) - TSC(Time Stamp Counter)와 QueryPerformanceCounter [12]파일 다운로드1
11067정성태10/18/201629295Windows: 123. 윈도우 운영체제의 시간 함수 (4) - RTC, TSC, PM Clock, HPET Timer [2]
11066정성태10/17/201628906Windows: 122. 윈도우 운영체제의 시간 함수 (3) - QueryInterruptTimePrecise, QueryInterruptTime 함수파일 다운로드1
... 106  107  108  109  110  111  112  113  114  115  116  [117]  118  119  120  ...