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?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- How to know full paths to DLL's from .csproj f
- Importing NuGet references through a local project
相关文章
- How to show location of errors, references to memb
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- How to track MongoDB requests from a console appli
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
_CONSOLE
should do the trick for you.Also you can select the subsystem using
#pragma comment( linker, "/subsystem:windows" )
or#pragma comment( linker, "/subsystem:console" )
if you really want to go this route.If you are trying to make things easy for users of your library (or whatever it is), you could just generate both
WinMain
andmain
from your macro. The linker by default sets console apps to start atmain
, and win32 apps to start atWinMain
. 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.That's not how it really works. You have to write dramatically different code in a console app vs a native Windows app. In a console app, you use printf or cout to produce output, don't have much if any use for a mouse. A native Windows app requires a message loop and creating a window with a window procedure that detects the WM_PAINT message to update the window. Etcetera.
But you can write code that does both. Just write both a main() and a WinMain() function, the CRT automatically calls the correct one.