环境:Window10,VS2019,c++
1、设置dll延迟加载
属性->配置属性->链接器->输入->延迟加载的Dll-> 添加MyDll.dll
属性->配置属性->链接器->输入->附加依赖项-> 添加MyDll.lib
2、引入头文件即可
#define _WIN32_WINNT 0x0502 // need for SetDllDirectory
#include
#include
#include "Wrapper.h"
void main()
{
SetDllDirectory(L"bin\\");//wrapper.dll在当前目录的bin文件夹中
TestWrapper();
/*HMODULE h = LoadLibrary(L"Wrapper.dll");
if(h)
{
typedef void (*PTest)();
PTest p = (PTest)GetProcAddress(h, "TestWrapper");
if(p)
{
p();
printf("\n-------------\nok!!!\n");
}
else
{
printf("\nGetProcAddress('TestWrapper') failed");
}
}
else
printf("\nLoad Wrapper.dll failed");*/
system("pause");
}