-
- #include "stdafx.h"
- #include <windows.h>
- #include <crtdbg.h>
-
-
- extern "C" int foo(void);
- extern "C" int foo1(void);
-
- static int gs_iTest = foo1();
- int g_iTest = foo();
-
- int main(int argc, char* argv[])
- {
- printf("&main = %p\n", &main);
- getchar();
- return 0;
- }
-
- extern "C" int foo(void)
- {
-
- MessageBox(NULL, "foo before main", "test", MB_OK);
- return 0;
- }
-
- extern "C" int foo1(void)
- {
-
- MessageBox(NULL, "foo1 before main", "test", MB_OK);
- return 0;
- }
效果



http://blog.csdn.net/lostspeed/article/details/49748951
在C++工程中main函数之前跑代码的廉价方法(使用全局变量和全局函数)
原文:http://www.cnblogs.com/findumars/p/5187285.html