C++global成员变量实现DllMain类似的调用

#include <iostream>
using namespace std;

class OGSModule
{
public:
    OGSModule()
    {
        cout 
<< "Say hello from Wentao inside shared library." << endl;
    }
    
    
~OGSModule()
    {
        cout 
<< "Goodbye, boy, thank you!" << endl;
    }
};

static OGSModule gDummy;

这样子在这部分代码在的模块被loading的时候,OGSModule的Ctor会被调用,而当模块被Unloading的时候,OGSModule的析构函数会被调用.

这个功能类似于 DllMain的功能.

相关文章:

  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-09-21
  • 2021-06-05
  • 2022-12-23
  • 2021-11-25
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-30
  • 2021-07-31
相关资源
相似解决方案