하단에 이전 답을 떠나 상단에 새로 추가 : 지연 로딩과이 문제를 해결할 수있는 좋은 방법을 제공에 설명 된대로 지연로드 Failure Hook의
조합을.
라이브러리에서 기호를 사용하기 전에 백업 dll을로드하는 실패 후크를 등록하십시오. 내가 무엇을 찾고 있었던 것은 지연 로딩처럼 ==============
아래
#include <Windows.h>
#include "foo.h"
#include <delayimp.h>
//access to set the failure hook
ExternC PfnDliHook __pfnDliFailureHook2;
const char* dllName = "foo.dll";
const char* dllBackupPath = "pathToBackup\\foo.dll";
FARPROC WINAPI DelayLoadHook(unsigned dliNotify, PDelayLoadInfo pdli)
{
//if the failure was failure to load the designated dll
if (dliNotify == dliFailLoadLib &&
strcmp(dllName, pdli->szDll) == 0 &&
pdli->dwLastError == ERROR_MOD_NOT_FOUND)
{
printf("loading back-up dll\n");
//return the successfully loaded back-up lib,
//or 0, the LoadLibrary fails here
HMODULE lib = LoadLibraryA(dllBackupPath);
return (FARPROC)lib;
}
return 0;
}
int main()
{
//set the Failure Hook
__pfnDliFailureHook2 = &DelayLoadHook;
//when this function is called the library will be loaded
//from standard paths. If it is not found the Failure Hook
//set above will be called.
int test = ::intReturningFuncFromFooDll();
printf("%d", test);
getchar();
return 0;
}
=========== 된 대답은 같은데 IInspectable에 의해 언급 된 바와 같이. 도움을
//load the dll using the normal search
HMODULE lib = LoadLibrary(L"foo.dll");
//if unsuccessful, try a specified path
if (lib == NULL)
{
LoadLibrary(L"mySpecifiedPath/foo.dll");
}
if (lib == NULL)
{
//make sure that the library is not used,
//or exit the application, as it was not found
}
감사 :
Linker Support for Delay-Loaded DLLs
은 여기가 원래의 게시물에서 언급 한 사용을 보여주는 몇 가지 코드입니다 : 나는이에 관한 정보를 발견!
이전 답변으로 편집 :이 동적 로딩은 라이브러리의 모든 기호를 사용하기 전에 사용됩니다. 로드 된 지연은 라이브러리의 심볼에 처음 액세스 할 때 여기에로드 된 모듈을 사용하여 심볼 주소를 채 웁니다.
지연로드를 활성화하고 응용 프로그램 시작 중에 DLL 검색 디렉토리를 일찍 설정할 수 있습니다. – IInspectable