VC修改了入口主函数,全局对象不构造问题?
问题描述:VC2013新建Win32 Console Application,全部代码如下,
编译运行,一切正常。运行结果为:
widget()
Hello World.
~widget()
Press any key to continue . . .
接下来修改项目属性,Linker-> Advanced-> Entry Point 设为 my_main,并对应的修改主函数名,修改后的代码如下,
编译,链接,有警告如下:
1>ConsoleApplication2.obj : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>MSVCRTD.lib(atonexit.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
运行结果为:
Hello World.
Press any key to continue . . .
可以看到,全局对象的构造函数和析构函数都没有调用。那么问题来了,如果我想修改主函数的名称,同时又希望全局对象像以前正常构造析构,该怎么做呢?
// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class CWidget
{
public:
CWidget()
{
_tprintf(_T("widget()\n"));
}
~CWidget()
{
_tprintf(_T("~widget()\n"));
}
};
CWidget widget;
int _tmain(int argc, _TCHAR* argv[])
{
_tprintf(_T("Hello World.\n"));
return 0;
}
编译运行,一切正常。运行结果为:
widget()
Hello World.
~widget()
Press any key to continue . . .
接下来修改项目属性,Linker-> Advanced-> Entry Point 设为 my_main,并对应的修改主函数名,修改后的代码如下,
// ConsoleApplication2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
class CWidget
{
public:
CWidget()
{
_tprintf(_T("widget()\n"));
}
~CWidget()
{
_tprintf(_T("~widget()\n"));
}
};
CWidget widget;
int my_main(int argc, _TCHAR* argv[])
{
_tprintf(_T("Hello World.\n"));
return 0;
}
编译,链接,有警告如下:
1>ConsoleApplication2.obj : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
1>MSVCRTD.lib(atonexit.obj) : warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators
运行结果为:
Hello World.
Press any key to continue . . .
可以看到,全局对象的构造函数和析构函数都没有调用。那么问题来了,如果我想修改主函数的名称,同时又希望全局对象像以前正常构造析构,该怎么做呢?
...全文
相关推荐
VC6字体列表不全和默认字体修改的补丁
VC6字体列表不全的问题补丁 VC6默认IDE字体难看的补丁 VC6启动界面的修改 VC6控件的美化
vc全局hook
vc全局hook,已经实现,代码有注释,打开hooktest\Release下的hooktest.exe程序后屏蔽鼠标,esc键可以退出程序,F2最小化,F3恢复。
VC全局钩子使用例子
SetWindowsHookEx()函数的使用实例,也即全局钩子的使用例子。除了代码外,32位和64位的dll和exe都没有删,可以下下来看看效果再编译。
Hook编程。如何安装钩子过程,如何编写全局钩子,动态连接库里的全局变量数据共享问题分析。ADO数据库编程。在VB中利用ADO控件和ADO对象访问数据库,在VC中利用ADO技术访问数据库。
Hook编程。如何安装钩子过程,如何编写全局钩子,动态连接库里的全局变量数据共享问题分析。ADO数据库编程。在VB中利用ADO控件和ADO对象访问数据库,在VC中利用ADO技术访问数据库。
VC6_FixFont修改VC6字体
VC6_FixFont修改VC6字体,点击写入注册表,可以对VC6的字体进行设置.


