On Thu, 12 Aug 2010 22:09:40 -0500, dickl <[email protected]> wrote:

On 8/11/2010 1:09 PM, Walter Bright wrote:
dickl wrote:
I should have been a little more clear, a static this() as a member of
a class.

Still works:
--------------------------

H:\cbx>type test.d

import std.stdio;

void main()
{
printf("hello\n");
}

class C
{
static this()
{
printf("betty\n");
}
}


H:\cbx>dmd test

H:\cbx>test
betty
hello

H:\cbx>

Looks like it might be windows specific. This doesn't work (only prints out "again"


import std.stdio;
import std.string;
import std.c.windows.windows;
import core.runtime;


extern (Windows) int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{

     try
     {
         Runtime.initialize();
         return myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow);


        }//end try

     catch (Object o)           // catch any uncaught exceptions
     {
MessageBoxA(null, toStringz(o.toString()), "Fatal Error", MB_OK | MB_ICONERROR);
     }finally
     {
         Runtime.terminate();
     }


     return 0;
}//end int WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)


int myWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

                foo f = new foo;
        
                return 1;
}//end int myWinMain HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)


class foo
{
public:
        static this()
        {
                writeln("Hello");
        }
        static ~this()
      {
        }
        this()
        {
                writefln(" again");
        }
}



You are mixing windows specific functions (WinMain) and console functions (writeln). This will either cause an exception or just fail to run. Try to replace calls to writeln with calls to MessageBox if you want to check if the static constructor/destructor is working correctly.

--
Yao G.

Reply via email to