to!string and windows programming
Phil Lavoie
maidenphil at hotmail.com
Mon Dec 24 10:21:55 PST 2012
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
More information about the Digitalmars-d-learn
mailing list