解决问题的一种方法是使用SetDllDirectory
函数;但是,它需要你在程序上执行的第一件事(这很难做到),我的解决方案是使用第三方程序来设置dll目录,然后调用你的EXE文件作为一个新进程:
这是第三方这将是一个EXE文件:
#include <windows.h>
SetDllDirectory(_T(".dll location"));
STARTUPINFOW siStartupInfo;
PROCESS_INFORMATION piProcessInfo;
memset(&siStartupInfo, 0, sizeof(siStartupInfo));
memset(&piProcessInfo, 0, sizeof(piProcessInfo));
siStartupInfo.cb = sizeof(siStartupInfo);
if (CreateProcessW(L".exe location",NULL, NULL, NULL, FALSE,
0, NULL, NULL,
&siStartupInfo, &piProcessInfo))
{
/* This line waits for the process to finish. */
/* You can omit it to keep going whilst the other process runs */
//dwExitCode = WaitForSingleObject(piProcessInfo.hProcess, (SecondsToWait * 1000));
}
else
{
/* CreateProcess failed */
//iReturnVal = GetLastError();
}
return 0;
我在这里的问题是,我将不得不延迟加载的DLL很多,当我们整合新的第三方模块列表经常改变。此外,如果所需的DLL不存在,我希望应用程序只启动失败,以便我可以修复它(而不是仅在实际尝试使用该DLL时发现该问题)。 – Warpin 2011-01-19 21:28:10