dll中的全局类实例什么时候初始化

如果外部工程ExeB调了动态库DllA中的函数,当ExeB运行时,DllA中的全局类实例一定会初始化,但不一定非得在ExeB中调DllA中的函数后DllA中的全局类实例才会初始化,比如在DllA中代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class DllA01()
{
public:
	DllA01()
	{
		MessageBoxA(NULL, "init", NULL, 0);
	}
	~DllA01()
	{
		MessageBoxA(NULL, "fini", NULL, 0);
	}
	void test(void)
	{
		MessageBoxA(NULL, "test", NULL, 0);
	}
};
__declspec(dllexport) DllA01 gA01;
extern "C" __declspec(dllexport) void dllA01Test(void)
{
	MessageBoxA(NULL, "dllA01Test", NULL, 0);
}

在ExeB中加入

1
2
3
4
#pragma comment(lib, "DllA.lib")
#pragma comment(linker, "/include:__imp__dllA01Test")
//#pragma comment(linker, "/include:__imp_?gA01@@3VDllA01@@A")
//#pragma comment(linker, "/ENTRY:foo")