On 10/12/2015 3:12 PM, Paavo Helde wrote:
> Christopher Pisz <
nos...@notanaddress.com> wrote in news:mvh0mc$3jv$1
> @
dont-email.me:
>
>>
>> I have some code in a library that needs to do one thing if it is being
>> run "in console mode" and it needs to do another thing if it is being
>> run as a "windows service"
>>
>> There is already a preprocessor definition in executables being run in
>> "console mode" put there by Visual Studio: _CONSOLE
>>
>> However, I quickly discovered that a #ifdef #else #endif block has
>> already been substituted when the library is compiled, in which case
>> _CONSOLE is not defined. It is defined when the executable is compiled,
>> which occurs after the library.
>
> Rightly so. When compiling the library, it is not known in what kind of
> application it will be run. If you want it be usable in both modes then
> you should find out at run-time which mode it is in, and branch at run-
> time, not at compile time with preprocessor. Surely there is a way to do
> that. You should also think over what exactly you want to detect, console
> mode or service mode (hint: 90+% of Windows applications are neither).
Now time to test. Thank you sir.