Is there a #define associated with the SubSystem

前端 未结 3 790
情书的邮戳
情书的邮戳 2021-01-08 00:42

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 appro

3条回答
  •  庸人自扰
    2021-01-08 01:25

    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.

提交回复
热议问题