digitalmars.D.learn - to!string and windows programming
- Phil Lavoie (42/42) Dec 24 2012 Yo,
- Andrej Mitrovic (9/12) Dec 24 2012 You need to initialize the runtime or you will get crashes as soon as
- Phil Lavoie (6/20) Dec 24 2012 Wow buddy thanks for the accurate and most informative answer. I
Yo, I am currently going through the much recommended book "Programming Windows" and experiencing some stuff. One of which was formatting the hInstance and prevHInstance into a string. WHICH CRASHES THE PROGRAM! I hope I am doing something wrong! Please scope the code below and let me know either the reason + workaround for this misbehaviour or what is my mistake! import std.stdio; version( Windows ) { import std.c.windows.windows; import std.string; import std.conv; extern( Windows ) int WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { //size_t noInstance = cast( size_t )hInstance; void * vp = null; size_t noInstance = cast( size_t )vp; string noInstanceS = to!string( noInstance ); //This line crashes /* MessageBoxA( null, //toStringz( "HInstance: " ~ to!string( hInstance ) ~ "\nHPrevInstance: " ~ to!string( hPrevInstance ) ), toStringz( "Hello" ), toStringz( "HelloIsMe" ), 0 ); */ return 0; } } else { import std.conv; void main( string[] args ) { void * vp = null; size_t vpInt = cast( size_t )vp; writeln( "VP: ", to!string( vpInt ) ); //Here it does not. } } Regards! Phil
Dec 24 2012
On 12/24/12, Phil Lavoie <maidenphil hotmail.com> wrote:I am currently going through the much recommended book "Programming Windows" and experiencing some stuff. One of which was formatting the hInstance and prevHInstance into a string.You need to initialize the runtime or you will get crashes as soon as the GC allocates memory. Note that many Programming Windows examples were translated into D and you can find them here: https://github.com/AndrejMitrovic/DWinProgramming Here's an example how the runtime is initialized: https://github.com/AndrejMitrovic/DWinProgramming/blob/master/Samples/Chap01/HelloMsg/HelloMsg.d See the `Runtime.initialize(&exceptionHandler);` call.
Dec 24 2012
On Monday, 24 December 2012 at 18:28:04 UTC, Andrej Mitrovic wrote:On 12/24/12, Phil Lavoie <maidenphil hotmail.com> wrote:Wow buddy thanks for the accurate and most informative answer. I will be looking through those examples. Thanks again! PhilI am currently going through the much recommended book "Programming Windows" and experiencing some stuff. One of which was formatting the hInstance and prevHInstance into a string.You need to initialize the runtime or you will get crashes as soon as the GC allocates memory. Note that many Programming Windows examples were translated into D and you can find them here: https://github.com/AndrejMitrovic/DWinProgramming Here's an example how the runtime is initialized: https://github.com/AndrejMitrovic/DWinProgramming/blob/master/Samples/Chap01/HelloMsg/HelloMsg.d See the `Runtime.initialize(&exceptionHandler);` call.
Dec 24 2012