- 在dll中声明
1 _declspec(dllexport) int a = 10;
1 _declspec(dllexport)void go() 2 { 3 4 MessageBoxA(0, "go", "go", 0); 5 6 }
- 调用dll
1 HINSTANCE hlib = LoadLibrary("DLL.dll");
- 获取
1 if (hlib!=NULL) 2 { 3 4 p = (void(*)())GetProcAddress(hlib, "go");//获取地址,强制转换 5 if (p!=NULL) 6 { 7 p(); 8 } 9 10 }
- 释放
1 FreeLibrary(hlib);