www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Windows startup docs are out of date

reply Manu <turkeyman gmail.com> writes:
--089e0153884892a47d04ef6805f1
Content-Type: text/plain; charset=UTF-8

http://dlang.org/windows.html

This doesn't work anymore. I don't know what the proper way to boot a Win32
app is.
Is it required to explicitly init the runtime?

--089e0153884892a47d04ef6805f1
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><a href=3D"http://dlang.org/windows.html">http://dlang.org=
/windows.html</a><br><div><br></div><div>This doesn&#39;t work anymore. I d=
on&#39;t know what the proper way to boot a Win32 app is.</div><div>Is it r=
equired to explicitly init the runtime?</div>
</div>

--089e0153884892a47d04ef6805f1--
Jan 07 2014
next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:
 This doesn't work anymore. I don't know what the proper way to 
 boot a Win32 app is.

The easiest way is to just write a regular program with a main() instead of a WinMain. If you need the args, you can get them from functions like GetModuleHandle, GetCommandLine, etc.
 Is it required to explicitly init the runtime?

If you want to use WinMain directly, yes, use Runtime.initalize before doing anything else. But I say regular main is much easier.
Jan 07 2014
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2014-01-07 22:29, Adam D. Ruppe wrote:

 The easiest way is to just write a regular program with a main() instead
 of a WinMain. If you need the args, you can get them from functions like
 GetModuleHandle, GetCommandLine, etc.

The runtime provides access to the command line arguments as well: core.Runtime.args core.Runtime.cArgs http://dlang.org/phobos/core_runtime.html -- /Jacob Carlborg
Jan 07 2014
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2014-01-08 01:32, Manu wrote:

 It didn't work for me. Said it was deprecated... and to use rt_init().
 Is there a difference? Why do Runtime.initialize() AND rt_init() both
 exist? I don't like pointless aliases... I freak out that there's some
 small difference that I don't understand.

rt_init() is to be used from C, so you don't have to bother with the D mangling. Runtime.initialize() is supposed to be used from D, you need to do something special about the boot process, which you normally doesn't. -- /Jacob Carlborg
Jan 07 2014
prev sibling parent reply Mike Parker <aldacron gmail.com> writes:
On 1/8/2014 6:29 AM, Adam D. Ruppe wrote:
 On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:
 This doesn't work anymore. I don't know what the proper way to boot a
 Win32 app is.

The easiest way is to just write a regular program with a main() instead of a WinMain. If you need the args, you can get them from functions like GetModuleHandle, GetCommandLine, etc.

The easiest way is to use main() and add this to the DMD command line: /SUBSYSTEM:WINDOWS:5.01 This will give you a windowed app with no console popping up *and* the command line args are still stored in Runtime.args and passed to the main method just as they are in a console app. Note that 5.01 is for 32-bit. 5.02 should be used when compiling for 64-bit.
Jan 08 2014
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2014-01-08 09:46, Mike Parker wrote:

 The easiest way is to use main() and add this to the DMD command line:

 /SUBSYSTEM:WINDOWS:5.01

 This will give you a windowed app with no console popping up *and* the
 command line args are still stored in Runtime.args and passed to the
 main method just as they are in a console app.

 Note that 5.01 is for 32-bit. 5.02 should be used when compiling for
 64-bit.

What's the original idea of WinMain anyway? -- /Jacob Carlborg
Jan 08 2014
prev sibling next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2014-01-08 12:17, Manu wrote:

 Right... well, I don't really care how it is, I just want the wiki to be
 updated with the 'standard' way. I will then copy and paste into my
 code, and ideally everyone's startup code will look the same.
 I have to say though, requiring additional linker arguments is pretty
 lame. I'd definitely rather not, if I was voting on a standard approach.

It's Windows that is lame. Every other platform uses a normal main function. -- /Jacob Carlborg
Jan 08 2014
parent Jacob Carlborg <doob me.com> writes:
On 2014-01-08 14:28, Adam D. Ruppe wrote:

 eh they're really in the same boat. Declaring your own WinMain is kinda
 like declaring your own _start symbol on linux. It skips the runtime's
 main() function and you're more on your own.

No, it's not. For C: Implementing WinMain does not bypass the runtime[1]. Implementing _start on Linux would most likely bypass the runtime. Implementing WinMain is more like implementing main() on Posix. For D: Implementing WinMain or main() as extern (C) will bypass the D runtime, it still won't bypass the C runtime. I would expect the boot process be something like this: Linux: _start C main D main Windows: CRT (C runtime library) C main or WinMain D main
 Both the C and the D runtimes implement their own entry point which
 calls into your program's main and you can use these consistently across
 platforms.

WinMain is not the entry point. The C runtime library will call it just like it will call C main. [1] http://msdn.microsoft.com/en-us/library/windows/desktop/ff381406%28v=vs.85%29.aspx -- /Jacob Carlborg
Jan 08 2014
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2014-01-08 12:17, Manu wrote:

 Right... well, I don't really care how it is, I just want the wiki to be
 updated with the 'standard' way. I will then copy and paste into my
 code, and ideally everyone's startup code will look the same.
 I have to say though, requiring additional linker arguments is pretty
 lame. I'd definitely rather not, if I was voting on a standard approach.

Using a standard main function allows you do use the same code on all platforms. You most likely will need different linker flags anyway. -- /Jacob Carlborg
Jan 08 2014
prev sibling parent Mike Parker <aldacron gmail.com> writes:
On 1/8/2014 8:17 PM, Manu wrote:

 Right... well, I don't really care how it is, I just want the wiki to be
 updated with the 'standard' way. I will then copy and paste into my
 code, and ideally everyone's startup code will look the same.
 I have to say though, requiring additional linker arguments is pretty
 lame. I'd definitely rather not, if I was voting on a standard approach.

It's the same with C or C++ apps, using any compiler on Windows. Anything with a 'main' entry point is automatically launched as console subsystem, anything with WinMain as windows subsystem. The command line argument allows you to override the default behavior. You could, for example, use a WinMain entry and specify /SUBSYSTEM:CONSOLE (or whatever the keyword is). I was surprised to learn when using premake with MinGW was that it automatically configured things to link all windows executables as subsystem windows. I got used to it when I mostly worked with C, so now in D all of my dub package.jsons for executables have a configurations section that looks something like this: "configurations": [ { "name": "foo", "targetType": "executable", "targetPath": "bin", "targetName": "foo" }, { "name": "foo-win", "targetType": "executable", "targetPath": "bin", "targetName": "foo", "lflags": ["/SUBSYSTEM:WINDOWS:5.01"] } ] The console version as default means during development I get a console window every time I launch the latest build (which is convenient for debug output) without having specified any extra args on the dub command line. Of course, for someone using VisualD it's not such a big deal. But I think adding a linker flag to the project settings is less work than maintaining two separate entry points :)
Jan 08 2014
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--001a11c2e064ad9f3004ef682ce3
Content-Type: text/plain; charset=UTF-8

On 8 January 2014 07:29, Adam D. Ruppe <destructionator gmail.com> wrote:

 On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:

 This doesn't work anymore. I don't know what the proper way to boot a
 Win32 app is.

The easiest way is to just write a regular program with a main() instead of a WinMain. If you need the args, you can get them from functions like GetModuleHandle, GetCommandLine, etc. Is it required to explicitly init the runtime?

If you want to use WinMain directly, yes, use Runtime.initalize before doing anything else. But I say regular main is much easier.

It complains and says to use rt_init(), and that exception handler thing is gone. I think that page needs to be updated by someone who knows how it should look. --001a11c2e064ad9f3004ef682ce3 Content-Type: text/html; charset=UTF-8 <div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 8 January 2014 07:29, Adam D. Ruppe <span dir="ltr">&lt;<a href="mailto:destructionator gmail.com" target="_blank">destructionator gmail.com</a>&gt;</span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> This doesn&#39;t work anymore. I don&#39;t know what the proper way to boot a Win32 app is.<br> </blockquote> <br></div> The easiest way is to just write a regular program with a main() instead of a WinMain. If you need the args, you can get them from functions like GetModuleHandle, GetCommandLine, etc.<div class="im"><br> <br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Is it required to explicitly init the runtime?<br> </blockquote> <br></div> If you want to use WinMain directly, yes, use Runtime.initalize before doing anything else. But I say regular main is much easier.<br> </blockquote></div><br></div><div class="gmail_extra">It complains and says to use rt_init(), and that exception handler thing is gone.</div><div class="gmail_extra">I think that page needs to be updated by someone who knows how it should look.</div> </div> --001a11c2e064ad9f3004ef682ce3--
Jan 07 2014
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 7 January 2014 at 21:37:05 UTC, Manu wrote:
 It complains and says to use rt_init(), and that exception 
 handler thing is gone.

blargh, well Runtime.initialize() without args works too.
 I think that page needs to be updated by someone who knows how 
 it should look.

Yeah, and it'd be good to add the note that doing your own WinMain isn't actually needed... and use MessageBoxW.
Jan 07 2014
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--001a11c2a20c4ef61a04ef6aa122
Content-Type: text/plain; charset=UTF-8

On 8 January 2014 07:43, Adam D. Ruppe <destructionator gmail.com> wrote:

 On Tuesday, 7 January 2014 at 21:37:05 UTC, Manu wrote:

 It complains and says to use rt_init(), and that exception handler thing
 is gone.

blargh, well Runtime.initialize() without args works too.

It didn't work for me. Said it was deprecated... and to use rt_init(). Is there a difference? Why do Runtime.initialize() AND rt_init() both exist? I don't like pointless aliases... I freak out that there's some small difference that I don't understand. I think that page needs to be updated by someone who knows how it should
 look.

Yeah, and it'd be good to add the note that doing your own WinMain isn't actually needed... and use MessageBoxW.

But yeah, it needs to be updated with the latest best practise. --001a11c2a20c4ef61a04ef6aa122 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 8= January 2014 07:43, Adam D. Ruppe <span dir=3D"ltr">&lt;<a href=3D"mailto:= destructionator gmail.com" target=3D"_blank">destructionator gmail.com</a>&= gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im">On Tuesday, 7 January 2014= at 21:37:05 UTC, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> It complains and says to use rt_init(), and that exception handler thing is= gone.<br> </blockquote> <br></div> blargh, well Runtime.initialize() without args works too.</blockquote><div>= <br></div><div>It didn&#39;t work for me. Said it was deprecated... and to = use rt_init().</div><div>Is there a difference? Why do Runtime.initialize()= AND rt_init() both exist? I don&#39;t like pointless aliases... I freak ou= t that there&#39;s some small difference that I don&#39;t understand.</div> <div><br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex= ;border-left:1px #ccc solid;padding-left:1ex"><div class=3D"im"> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> I think that page needs to be updated by someone who knows how it should lo= ok.<br> </blockquote> <br></div> Yeah, and it&#39;d be good to add the note that doing your own WinMain isn&= #39;t actually needed... and use MessageBoxW.<br> </blockquote></div><br></div><div class=3D"gmail_extra">But yeah, it needs = to be updated with the latest best practise.</div></div> --001a11c2a20c4ef61a04ef6aa122--
Jan 07 2014
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 8 January 2014 at 00:32:56 UTC, Manu wrote:
 It didn't work for me. Said it was deprecated... and to use 
 rt_init().

Huh, the message I got is: winmain.d(13): Deprecation: function core.runtime.Runtime.initialize is deprecated - Please use the overload of Runtime.initialize that takes no argument. Maybe different dmd versions. Oh well.
 Is there a difference?

The source tells: static bool initialize() { return !!rt_init(); } /// C interface for Runtime.initialize, returns 1/0 instead of bool extern(C) int rt_init(); So no real difference.
 Why do Runtime.initialize() AND rt_init() both exist?

idk
Jan 07 2014
prev sibling next sibling parent Jacob Carlborg <doob me.com> writes:
On 2014-01-07 22:25, Manu wrote:
 http://dlang.org/windows.html

 This doesn't work anymore. I don't know what the proper way to boot a
 Win32 app is.
 Is it required to explicitly init the runtime?

I started to think about this some more and I agree with Adam, just use a regular D main function. -- /Jacob Carlborg
Jan 07 2014
prev sibling next sibling parent "eles" <eles eles.com> writes:
On Wednesday, 8 January 2014 at 10:15:30 UTC, Jacob Carlborg 
wrote:
 On 2014-01-08 09:46, Mike Parker wrote:

 The easiest way is to use main() and add this to the DMD 
 command line:

 /SUBSYSTEM:WINDOWS:5.01

 This will give you a windowed app with no console popping up 
 *and* the
 command line args are still stored in Runtime.args and passed 
 to the
 main method just as they are in a console app.

 Note that 5.01 is for 32-bit. 5.02 should be used when 
 compiling for
 64-bit.

What's the original idea of WinMain anyway?

http://stackoverflow.com/a/2399064/1284631
Jan 08 2014
prev sibling next sibling parent Manu <turkeyman gmail.com> writes:
--001a1133407e7e708104ef73a22a
Content-Type: text/plain; charset=UTF-8

On 8 January 2014 18:46, Mike Parker <aldacron gmail.com> wrote:

 On 1/8/2014 6:29 AM, Adam D. Ruppe wrote:

 On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:

 This doesn't work anymore. I don't know what the proper way to boot a
 Win32 app is.

The easiest way is to just write a regular program with a main() instead of a WinMain. If you need the args, you can get them from functions like GetModuleHandle, GetCommandLine, etc.

/SUBSYSTEM:WINDOWS:5.01 This will give you a windowed app with no console popping up *and* the command line args are still stored in Runtime.args and passed to the main method just as they are in a console app. Note that 5.01 is for 32-bit. 5.02 should be used when compiling for 64-bit.

Right... well, I don't really care how it is, I just want the wiki to be updated with the 'standard' way. I will then copy and paste into my code, and ideally everyone's startup code will look the same. I have to say though, requiring additional linker arguments is pretty lame. I'd definitely rather not, if I was voting on a standard approach. --001a1133407e7e708104ef73a22a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 8= January 2014 18:46, Mike Parker <span dir=3D"ltr">&lt;<a href=3D"mailto:al= dacron gmail.com" target=3D"_blank">aldacron gmail.com</a>&gt;</span> wrote= :<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-le= ft:1px #ccc solid;padding-left:1ex"> <div class=3D"im">On 1/8/2014 6:29 AM, Adam D. Ruppe wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> On Tuesday, 7 January 2014 at 21:26:07 UTC, Manu wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> This doesn&#39;t work anymore. I don&#39;t know what the proper way to boot= a<br> Win32 app is.<br> </blockquote> <br> The easiest way is to just write a regular program with a main() instead<br=


<br> </blockquote> <br></div> The easiest way is to use main() and add this to the DMD command line:<br> <br> /SUBSYSTEM:WINDOWS:5.01<br> <br> This will give you a windowed app with no console popping up *and* the comm= and line args are still stored in Runtime.args and passed to the main metho= d just as they are in a console app.<br> <br> Note that 5.01 is for 32-bit. 5.02 should be used when compiling for 64-bit= .<br></blockquote><div><br></div><div>Right... well, I don&#39;t really car= e how it is, I just want the wiki to be updated with the &#39;standard&#39;= way. I will then copy and paste into my code, and ideally everyone&#39;s s= tartup code will look the same.</div> <div>I have to say though, requiring additional linker arguments is pretty = lame. I&#39;d definitely rather not, if I was voting on a standard approach= .</div></div></div></div> --001a1133407e7e708104ef73a22a--
Jan 08 2014
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 8 January 2014 at 11:17:24 UTC, Manu wrote:
 I have to say though, requiring additional linker arguments is 
 pretty lame.

They aren't really required, the program will work without them, the linker argument tells the operating system not to allocate a console for this process. That's not always wanted; I like having a console for printf debugging even with a gui. But on my system, I made a separate little script that adds the linker argument so I don't type it out often when I want that. You might consider doing the same. BTW I think dmd should have more linker pragmas though. I wouldn't mind a pragma(windows_subsystem, "windows") as well as things like pragma(manifest, "<some xml>") or pragma(resource) or pragma(module_definition) and so on. But eh I can see the arguments against these too.
Jan 08 2014
prev sibling next sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 8 January 2014 at 12:50:54 UTC, Jacob Carlborg 
wrote:
 It's Windows that is lame. Every other platform uses a normal 
 main function.

eh they're really in the same boat. Declaring your own WinMain is kinda like declaring your own _start symbol on linux. It skips the runtime's main() function and you're more on your own. Both the C and the D runtimes implement their own entry point which calls into your program's main and you can use these consistently across platforms.
Jan 08 2014
prev sibling parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Wednesday, 8 January 2014 at 14:11:50 UTC, Jacob Carlborg 
wrote:
 Implementing WinMain does not bypass the runtime[1].

Ah, now I know, thanks!
 Implementing _start on Linux would most likely bypass the 
 runtime.

Yeah, I know that does since I do it with gcc -nostdlib a lot. I was wrong about Windows though.
Jan 08 2014