本文介绍了WinMain,main和DllMain在C ++中的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这三个函数与何时使用它们有何区别?

What is the difference between the three functions and when to use them??

推荐答案

WinMain用于应用程序结束.exe)以指示进程正在启动。它将为进程提供命令行参数,并用作进程的用户代码入口点。 WinMain(或不同版本的main)也是一个必需的函数。 OS需要一个函数来调用以启动一个进程运行。

WinMain is used for an application (ending .exe) to indicate the process is starting. It will provide command line arguments for the process and serves as the user code entry point for a process. WinMain (or a different version of main) is also a required function. The OS needs a function to call in order to start a process running.

DllMain用于DLL来表示许多不同的场景。最引人注目的是,它会在

DllMain is used for a DLL to signify a lot of different scenarios. Most notably, it will be called when


  1. 时被调用。DLL被加载到进程中:DLL_PROCESS_ATTACH

  2. 从过程中卸载DLL:DLL_PROCESS_DETACH

  3. 在进程中启动了一个线程:DLL_THREAD_ATTACH

  4. 线程在进程中结束:DLL_THREAD_DETACH

  1. The DLL is loaded into the process: DLL_PROCESS_ATTACH
  2. The DLL is unloaded from the process: DLL_PROCESS_DETACH
  3. A thread is started in the process: DLL_THREAD_ATTACH
  4. A thread is ended in the process: DLL_THREAD_DETACH

DllMain是一个可选的构造,并且有很多隐式契约。例如,你不应该调用将强制另一个DLL加载的代码。一般来说,它是相当困难的功能得到正确,应该避免,除非你有非常具体的需求。

DllMain is an optional construct and has a lot of implicit contracts associated with it. For instance, you should not be calling code that will force another DLL to load. In general it's fairly difficult function to get right and should be avoided unless you have a very specific need for it.

这篇关于WinMain,main和DllMain在C ++中的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 18:42