是否有与子系统关联的#define [英] Is there a #define associated with the SubSystem
问题描述
我正在使用宏创建main,并且需要能够在编译时检查所选的SubSystem/SUBSYSTEM:WINDOWS或/SUBSYSTEM:CONSOLE,以便生成适当的main函数.有#define我可以检查是否可以完成此操作?
如果您想使您的库用户(或其他任何人)使用起来容易一些,则可以只从中生成WinMain
和main
您的宏.默认情况下,链接器将控制台应用程序设置为从main
开始,而将win32应用程序设置为从WinMain
开始.另一个主要"功能将被忽略.
(如果其余两个代码都可以使用,则其余代码可能不使用任何主要函数参数(argc
,argv
,hInstance
等).)
可以使用_CONSOLE
定义,但是它不会自动出现.您必须手动将其添加到项目属性中.另一方面,启动符号的选择是自动的.因此,仅提供这两种功能并选择链接器,可能会使工作变得更轻松,因为项目创建者无需进行任何设置,并且确实可以从Windows切换到控制台应用程序(甚至可以按配置),而无需执行任何操作任何东西.
I'm creating main with a macro and need to be able to check the selected SubSystem at compile time, /SUBSYSTEM:WINDOWS or /SUBSYSTEM:CONSOLE, in order to generate the appropriate main function. Is there a #define I can check that accomplishes this?
If you are trying to make things easy for users of your library (or whatever it is), you could just generate both WinMain
and main
from your macro. The linker by default sets console apps to start at main
, and win32 apps to start at WinMain
. The other "main" function will be ignored.
(Presumably the rest of the code doesn't use any of the main function arguments (argc
, argv
, hInstance
, etc.), if it's to work with both.)
The _CONSOLE
define could be used, but it doesn't appear automatically; you have to add it manually in to the project properties. The selection of startup symbol, on the other hand, is automatic. So just providing both functions, and letting the linker pick, might make life easier, because the project creator doesn't have to set anything up, and can indeed switch from windows to console app (possibly even per-configuration) without having to do anything.
这篇关于是否有与子系统关联的#define的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!