zoukankan      html  css  js  c++  java
  • 使用Boost的DLL库管理动态链接库(类似于Qt中的QLibrary)

    Boost 1.61新增了一个DLL库,跟Qt中的QLibrary类似,提供了跨平台的动态库链接库加载、调用等功能。
    http://www.boost.org/users/history/version_1_61_0.html

    编写一个Test.dll,导出方法Add

    [cpp] view plain copy
     
    1. INT WINAPI Add(INT x, INT y)    
    2. {    
    3.     return x + y;    
    4. }  


    加载、检查导出方法是否存在、调用方法、卸载应该是最常用的功能了。

    [cpp] view plain copy
     
      1. int main()    
      2. {    
      3.     auto libPath = "D:\Test.dll";    
      4.     
      5.     boost::dll::shared_library lib(libPath);    
      6.     lib.has("add");  // false。符号名称是大小写敏感的    
      7.     if (lib.has("Add"))    
      8.     {    
      9.         auto& symbol = lib.get<int __stdcall(int, int)>("Add");    
      10.         std::cout << symbol(5, 10) << std::endl;    
      11.     }    
      12.     
      13.     boost::dll::shared_library lib2;    
      14.     lib2.load(libPath);    
      15.     if (lib2.is_loaded())    
      16.     {    
      17.         auto& symbol = lib.get<int __stdcall(int, int)>("Add");    
      18.         std::cout << symbol(3, 5) << std::endl;    
      19.         lib2.unload();    
      20.     }    
      21.     
      22.     system("pause");    
      23.     return 0;    
      24. }  

    http://blog.csdn.net/aqtata/article/details/51780423

  • 相关阅读:
    [ZJOI2014]力
    [八省联考2018]劈配
    [APIO2007]动物园
    [九省联考2018]IIIDX
    [HAOI2015]树上染色
    [SHOI2008]堵塞的交通
    暑假第五周
    暑假第四周
    暑假第三周
    暑假第二周
  • 原文地址:https://www.cnblogs.com/findumars/p/6810138.html
Copyright © 2011-2022 走看看