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

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的功能.

posted on 2009-06-15 17:42  SunWentao  阅读(587)  评论(0编辑  收藏  举报