Abstractioning away main/winMain

Prudence via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Sep 4 18:43:42 PDT 2015


Standard and Win32 apps are so old school!

I'd like to hide WinMain by wrapping it in an application 
class(more or less).

Essentially I have an Application class

class Application
{
    public static Application New(void delegate() entry)
    {

    }
}


.... Another module

extern (Windows) int WinMain(...)
{


}

.... User Module:


const MyApp = Application.New({ std.stdio.writeln("MY APP IS 
COOL"); });


But the lamba runs into a problem because of the static nature of 
the program... much less figuring out how to hook WinMain up into 
it.

Essentially I don't want the user ever to have to know how there 
entry point came into being but there is this funkyness about it 
because Application never gets any control to call the user's 
Entry function. Whats worse is that D tries to evaluate the 
lambda at compile time. It's as if D only allows non-static data 
inside functions.


The idea is to have WinMain actually call the Entry lamba 
function once it gets ran(transfer control)... but this seems to 
be difficult or impossible with D and I'm not sure why or, if 
not, how to get it to work without having to make the user jump 
through hoops.

I suppose I could create the Application(Using New instead of 
new) inside of WinMain, but the issue still remains on how to get 
the user entry point(I suppose some compile time reflection could 
be used?).

Any ideas?

(The main reason for doing this is to make it easier for writing 
portable apps)






More information about the Digitalmars-d-learn mailing list