www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - winsamp refactored

I was promped to try creating a Windows application in D recently and was struck
by how complicated winsamp made it seem--no user should ever have to copy
portions of proprietary runtime code (dmain2) to make her D app work.  This is
an alternate method I cooked up that works equally well and show be a bit more
portable:

# import sys.windows.c.windows;
#
# /*
#  * Pass on all the real work to the standard main function.
#  */
# extern (C) int main( int argc, char **argv );
# 
# extern (Windows) int WinMain( HINSTANCE hInstance,
#         	                  HINSTANCE hPrevInstance,
# 	                          LPSTR     lpCmdLine,
# 	                          int       nCmdShow )
# {
#     return main( 1, &lpCmdLine );
# }
# 
# /*
#  * Define your D main function as usual.  This will be called through
#  * the extern(C) main function called above.  That's it!
#  */
# void main()
# {
# 
# }

A working sample using this method (based on samples.d.winsamp bundled with DMD)
is available here:

http://home.f4.ca/sean/d/winsamp.zip

Sean
Sep 21 2005