如何在Visual Studio中找到应用程序入口点(c++)

时间:2022-09-25 00:37:39

The question may apply to any programming language written in Visual Studio, but I am more concerned about C++.

这个问题可能适用于在Visual Studio中编写的任何编程语言,但是我更关心c++。

Is there a way to easily determine the application entry point in Visual Studio?

是否有一种方法可以轻松确定Visual Studio中的应用程序入口点?

For a relatively small application this could be easy, but for large ones, it will be pretty hard. In my particular case I know that the project which is set as startup is the one which has the entry point, but I was unable to find it, even the application starts and runs well.

对于一个相对较小的应用程序来说,这可能很简单,但是对于大型的应用程序来说,这将是非常困难的。在我的特殊情况下,我知道作为启动的项目是有入口点的项目,但是我找不到它,即使应用程序启动和运行良好。

3 个解决方案

#1


1  

When desiring to stop execution at the top of the main/WinMain function while interactively debugging a process on Windows, I typically just use F10/F11 (assuming default C/C++ key bindings in the Visual Studio IDE) to instruct the debugger to single-step (which starts the process, then performs the step, then breaks).

当想要在主/WinMain函数的顶部停止执行,同时在Windows上交互调试一个进程时,我通常只使用F10/F11(在Visual Studio IDE中假设默认的C/ c++键绑定)来指示调试器到单步(启动进程,然后执行步骤,然后中断)。

Note this may not always do what you want. If you want to catch global initializations, object constructions, etc, these are already done before reaching main or WinMain. Those require additional debugging and setting breakpoints in CRT-source code for the real global startup code (which eventually calls your main or WinMain). But if you simply want to break-on-main-entry for a program built with debugging symbols, this is likely the easiest way to do it.

注意,这可能并不总是做你想做的事情。如果您想要捕获全局初始化、对象结构等,那么在到达main或WinMain之前就已经完成了。这些需要额外的调试,并为真正的全局启动代码(最终调用您的主或WinMain)的crt源代码中设置断点。但是,如果您只是想要为一个用调试符号构建的程序的主条目,这可能是最简单的方法。

#2


2  

In C++, a fully compiled program can have only one defined main method. If there's more than one, the compiler will complain about "multiple definitions of main" or some other similarly worded message.

在c++中,一个完全编译的程序只能有一个定义的主方法。如果有不止一个,编译器会抱怨“main”的“多重定义”或其他类似的措辞。

So, the simplest option is to do a search for the symbol main (or, if compiling as a Windows Subsystem program, WinMain) and figure out which ones correspond to the "startup" project. There shouldn't be that many, even in a relatively large solution.

因此,最简单的方法是搜索符号main(或者,如果编译为Windows子系统程序,WinMain),并找出对应于“启动”项目的代码。不应该有那么多,即使是在一个相对较大的解决方案中。

#3


2  

If you want to find what C++ project is executable than search for <ConfigurationType>Application</ConfigurationType> in all your *.vcxproj files.

如果你想知道c++项目是可执行的,而不是在你所有的*中搜索 应用程序 。vcxproj文件。

If you are looking for the entry point function inside this application, than search for main, wmain or WinMain functions.

如果您正在寻找这个应用程序中的入口点函数,而不是搜索main、wmain或WinMain函数。

Also entry point can be redefined with /ENTRY parameter, so you can check Configuration Properties > Linker > Advanced > Entry Point project parameter or search for /ENTRY in your *.vcxproj.

也可以通过/ entry参数重新定义入口点,因此您可以检查配置属性> Linker >高级>入口点项目参数或在*.vcxproj中搜索/条目。

#1


1  

When desiring to stop execution at the top of the main/WinMain function while interactively debugging a process on Windows, I typically just use F10/F11 (assuming default C/C++ key bindings in the Visual Studio IDE) to instruct the debugger to single-step (which starts the process, then performs the step, then breaks).

当想要在主/WinMain函数的顶部停止执行,同时在Windows上交互调试一个进程时,我通常只使用F10/F11(在Visual Studio IDE中假设默认的C/ c++键绑定)来指示调试器到单步(启动进程,然后执行步骤,然后中断)。

Note this may not always do what you want. If you want to catch global initializations, object constructions, etc, these are already done before reaching main or WinMain. Those require additional debugging and setting breakpoints in CRT-source code for the real global startup code (which eventually calls your main or WinMain). But if you simply want to break-on-main-entry for a program built with debugging symbols, this is likely the easiest way to do it.

注意,这可能并不总是做你想做的事情。如果您想要捕获全局初始化、对象结构等,那么在到达main或WinMain之前就已经完成了。这些需要额外的调试,并为真正的全局启动代码(最终调用您的主或WinMain)的crt源代码中设置断点。但是,如果您只是想要为一个用调试符号构建的程序的主条目,这可能是最简单的方法。

#2


2  

In C++, a fully compiled program can have only one defined main method. If there's more than one, the compiler will complain about "multiple definitions of main" or some other similarly worded message.

在c++中,一个完全编译的程序只能有一个定义的主方法。如果有不止一个,编译器会抱怨“main”的“多重定义”或其他类似的措辞。

So, the simplest option is to do a search for the symbol main (or, if compiling as a Windows Subsystem program, WinMain) and figure out which ones correspond to the "startup" project. There shouldn't be that many, even in a relatively large solution.

因此,最简单的方法是搜索符号main(或者,如果编译为Windows子系统程序,WinMain),并找出对应于“启动”项目的代码。不应该有那么多,即使是在一个相对较大的解决方案中。

#3


2  

If you want to find what C++ project is executable than search for <ConfigurationType>Application</ConfigurationType> in all your *.vcxproj files.

如果你想知道c++项目是可执行的,而不是在你所有的*中搜索 应用程序 。vcxproj文件。

If you are looking for the entry point function inside this application, than search for main, wmain or WinMain functions.

如果您正在寻找这个应用程序中的入口点函数,而不是搜索main、wmain或WinMain函数。

Also entry point can be redefined with /ENTRY parameter, so you can check Configuration Properties > Linker > Advanced > Entry Point project parameter or search for /ENTRY in your *.vcxproj.

也可以通过/ entry参数重新定义入口点,因此您可以检查配置属性> Linker >高级>入口点项目参数或在*.vcxproj中搜索/条目。