1.添加delayimp.lib
2.添加要延迟加载的dll
3.设置卸载选项。
4.多个dll放置的目录设置
如下:
2.
3.
4.设置dll延迟加载的目录
class CDelayDll
{
public:
CDelayDll()
{
TCHAR tmp[MAX_PATH] = {0};
unsigned long size = ::GetModuleFileName(GetModuleHandle("xDataProxy.dll"),tmp,MAX_PATH);
if(MAX_PATH == size) return;
char dir[MAX_PATH];
char drive[_MAX_DRIVE];
::_splitpath_s( tmp, drive, 3, dir, MAX_PATH, NULL, 0, NULL, 0 );
::_makepath_s(tmp, MAX_PATH, drive, dir, NULL, NULL );
std::string strTemp = tmp;
tmp[strTemp.size()-1] = 0;
strTemp = tmp;
unsigned nPos = strTemp.rfind("\\");
if (nPos ==std::string::npos)
{
nPos = strTemp.rfind("//");
}
//在硬盘的根目录下则出错
if (nPos > 3)
{
strTemp = strTemp.substr(0,nPos+1);
strTemp += "plugins\\";
SetDllDirectory(strTemp.c_str());
}
}
} g_initDelayDLL;
编译运行,OK!!