다음을 통해 공유


지연 로드할 DLL 지정

업데이트: 2007년 11월

링커 옵션 /DELAYLOAD:dllname을 사용하여 지연 로드할 DLL을 지정할 수 있습니다. 직접 작성한 도우미 함수를 사용하지 않는 경우 Delayimp.lib를 사용하여 프로그램을 링크해야 합니다.

다음은 DLL을 지연 로드하는 간단한 예제입니다.

// cl t.cpp user32.lib delayimp.lib  /link /DELAYLOAD:user32.dll
#include <windows.h>
// uncomment these lines to remove .libs from command line
// #pragma comment(lib, "delayimp")
// #pragma comment(lib, "user32")

int main() {
   // user32.dll will load at this point
   MessageBox(NULL, "Hello", "Hello", MB_OK);
}

프로젝트의 DEBUG 버전을 빌드합니다. 디버거를 사용하여 코드를 단계별로 실행하면 MessageBox를 호출할 때만 user32.dll이 로드됩니다.

참고 항목

개념

링커의 지연 로드된 DLL 지원