[cpp] view plain copy
- INT WINAPI Add(INT x, INT y)
- {
- return x + y;
- }
加载、检查导出方法是否存在、调用方法、卸载应该是最常用的功能了。
[cpp] view plain copy
- int main()
- {
- auto libPath = "D:\\Test.dll";
- boost::dll::shared_library lib(libPath);
- lib.has("add"); // false。符号名称是大小写敏感的
- if (lib.has("Add"))
- {
- auto& symbol = lib.get<int __stdcall(int, int)>("Add");
- std::cout << symbol(5, 10) << std::endl;
- }
- boost::dll::shared_library lib2;
- lib2.load(libPath);
- if (lib2.is_loaded())
- {
- auto& symbol = lib.get<int __stdcall(int, int)>("Add");
- std::cout << symbol(3, 5) << std::endl;
- lib2.unload();
- }
- system("pause");
- return 0;
- }