Re: Version for windows/console compilation?

2015-09-11 Thread Adam D. Ruppe via Digitalmars-d-learn

On Friday, 11 September 2015 at 04:30:44 UTC, Prudence wrote:
I'm using Visual D and I assume it takes care of all this. It 
works so that's not a huge problem.


If it is taking care of the linker switch, then you gain nothing 
but more complicated and fragile code by writing a WinMain!


I was hoping D had a flag to disambiguate console and windows 
apps(or some type to CT way to check).


There's not really a difference between them. A console app can 
create windows and a gui app can allocate a console.


The best thing to check for might just be if there's already a 
console available when you want to use one.


Re: Version for windows/console compilation?

2015-09-11 Thread Mike Parker via Digitalmars-d-learn

On Friday, 11 September 2015 at 04:30:44 UTC, Prudence wrote:


I'm simply creating my own version flags in VD properties. Not 
the best way because I'll have to remember to set the flags 
every time I use the library or I'll get errors about stuff 
missing. I was hoping D had a flag to disambiguate console and 
windows apps(or some type to CT way to check).


The subsystem is set at link time, so there is no reliable way at 
compile time to determine the configuration. A simple and cheap 
runtime check can be made like this:


import core.sys.windows.windows : GetConsoleCP;
bool hasConsole = !!GetConsoleCP();




Re: Version for windows/console compilation?

2015-09-10 Thread Adam D. Ruppe via Digitalmars-d-learn

On Thursday, 10 September 2015 at 18:06:43 UTC, Prudence wrote:
Is there a flag for knowing when a project is compiling for 
windows(Uses WinMain) vs a console(normal main)?


You'd have to choose the main yourself anyway, so document what 
process you use for that for people to use.


BTW it is pretty rare that you should actually write a WinMain in 
D. The right thing to do in most cases is to write a normal main 
function. You can still get the windows gui subsystem with a 
linker flag.


Version for windows/console compilation?

2015-09-10 Thread Prudence via Digitalmars-d-learn
Is there a flag for knowing when a project is compiling for 
windows(Uses WinMain) vs a console(normal main)?


version(Windows) is always valid for a console app, so it is 
useless to disambiguate between a console app and a windows app. 
(Say I have both a main and a winmain in my code, I need to 
select between them(it's a bit more complex than this but)).





Re: Version for windows/console compilation?

2015-09-10 Thread Mike Parker via Digitalmars-d-learn
On Thursday, 10 September 2015 at 18:10:43 UTC, Adam D. Ruppe 
wrote:


BTW it is pretty rare that you should actually write a WinMain 
in D. The right thing to do in most cases is to write a normal 
main function. You can still get the windows gui subsystem with 
a linker flag.


Specifically, add the following when using the Microsoft linker 
(compiling with -m64 or -m32mscoff):


-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup

And this when using OPTLINK:

-L/SUBSYSTEM:windows,5.01

The version numbers are optional. I use 6.00 with the MS linker 
because it covers both 32-bit and 64-bit apps on Vista and later, 
and is the default for the VS 2015 linker.


[1] https://msdn.microsoft.com/en-us/library/fcc1zstk.aspx

I don't think I've written a WinMain in D in 10 years.


Re: Version for windows/console compilation?

2015-09-10 Thread Prudence via Digitalmars-d-learn

On Friday, 11 September 2015 at 01:36:31 UTC, Mike Parker wrote:
On Thursday, 10 September 2015 at 18:10:43 UTC, Adam D. Ruppe 
wrote:


BTW it is pretty rare that you should actually write a WinMain 
in D. The right thing to do in most cases is to write a normal 
main function. You can still get the windows gui subsystem 
with a linker flag.


Specifically, add the following when using the Microsoft linker 
(compiling with -m64 or -m32mscoff):


-L/SUBSYSTEM:windows,6.00 -L/ENTRY:mainCRTStartup

And this when using OPTLINK:

-L/SUBSYSTEM:windows,5.01

The version numbers are optional. I use 6.00 with the MS linker 
because it covers both 32-bit and 64-bit apps on Vista and 
later, and is the default for the VS 2015 linker.


[1] https://msdn.microsoft.com/en-us/library/fcc1zstk.aspx

I don't think I've written a WinMain in D in 10 years.


I'm using Visual D and I assume it takes care of all this. It 
works so that's not a huge problem.


I'm simply creating my own version flags in VD properties. Not 
the best way because I'll have to remember to set the flags every 
time I use the library or I'll get errors about stuff missing. I 
was hoping D had a flag to disambiguate console and windows 
apps(or some type to CT way to check).