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