Thread overview | |||||
---|---|---|---|---|---|
|
December 24, 2012 to!string and windows programming | ||||
---|---|---|---|---|
| ||||
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 |
December 24, 2012 Re: to!string and windows programming | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phil Lavoie | 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. |
December 24, 2012 Re: to!string and windows programming | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Monday, 24 December 2012 at 18:28:04 UTC, Andrej Mitrovic wrote:
> 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.
Wow buddy thanks for the accurate and most informative answer. I will be looking through those examples.
Thanks again!
Phil
|
Copyright © 1999-2021 by the D Language Foundation