_WinMainCRTStartup执行什么功能? [英] What functions does _WinMainCRTStartup perform?

查看:453
本文介绍了_WinMainCRTStartup执行什么功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是至少两个紧密相关但截然不同的问题系列的一部分。我希望我可以通过分别询问他们来做正确的事情。

我正在尝试使Visual C ++ 2008应用程序在没有C运行时的情况下工作图书馆。这是一个Win32 GUI应用程序,没有MFC或其他精美的东西,只是普通的Windows API。

I'm trying to get my Visual C++ 2008 app to work without the C Runtime Library. It's a Win32 GUI app without MFC or other fancy stuff, just plain Windows API.

所以我设置了Project Properties-> Configuration-> C / C ++-> Advanced->将默认库名称省略为是(编译器标志 / Zl )并重建。

So I set Project Properties -> Configuration -> C/C++ -> Advanced -> Omit Default Library Names to Yes (compiler flag /Zl) and rebuilt.

然后,链接程序会抱怨未解决外部 _WinMainCRTStartup 。公平地说,我可以告诉链接器使用其他入口点,例如 MyStartup 。根据我在网络上收集到的信息, _WinMainCRTStartup 做一些初始化工作,我可能希望 MyStartup 做一部分

Then the linker complains about an unresolved external _WinMainCRTStartup. Fair enough, I can tell the linker to use a different entry point, say MyStartup. From what I gather around the web, _WinMainCRTStartup does some initialization stuff, and I probably want MyStartup to do a subset of that.

所以我的问题是: _WinMainCRTStartup 有什么功能,我可以执行哪些功能?省略我是否不使用CRT吗?

So my question is: What functions does _WinMainCRTStartup perform, and which of these can I omit if I don't use the CRT?

如果您了解这些知识,请查看我的其他问题。谢谢!

If you are knowledgeable about this stuff, please have a look at my other question too. Thanks!

另外:为什么我要这样做?


  1. 我的应用程序未明确使用任何CRT功能。

  2. 我喜欢精简和卑鄙的应用程序。

  3. 它将教我一些新知识。


推荐答案

CRT的入口点确实以下内容(此列表不完整):

The CRT's entry point does the following (this list is not complete):


  • 初始化CRT所需的全局状态。如果不这样做,则不能使用CRT提供的任何功能或状态。

  • 初始化一些编译器使用的全局状态。诸如/ GS使用的安全性cookie之类的运行时检查肯定在这里很突出。但是,您可以自己调用 __security_init_cookie 。您可能需要添加其他代码来进行其他运行时检查。

  • 在C ++对象上调用构造函数。如果您正在编写C ++代码,则可能需要对此进行仿真。

  • 检索命令行并启动OS提供的信息并将其传递给您的main。默认情况下,操作系统不会将任何参数传递给程序的入口点-它们都由CRT提供。

  • Initializes global state needed by the CRT. If this is not done, you cannot use any functions or state provided by the CRT.
  • Initializes some global state that is used by the compiler. Run-time checks such as the security cookie used by /GS definitely stands out here. You can call __security_init_cookie yourself, however. You may need to add other code for other run-time checks.
  • Calls constructors on C++ objects. If you are writing C++ code, you may need to emulate this.
  • Retrieves command line and start up information provided by the OS and passes it your main. By default, no parameters are passed to the entry point of the program by the OS - they are all provied by the CRT.

Visual Studio提供了CRT源代码,您可以在调试器中逐步浏览CRT的入口点,并确切地了解其作用。

The CRT source code is available with Visual Studio and you can step through the CRT's entry point in a debugger and find out exactly what it is doing.

这篇关于_WinMainCRTStartup执行什么功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆