What is wrong with this boilerplate mixin? (1/1)
Max Samuha
maxter at i.com.ua
Tue Oct 24 14:35:52 PDT 2006
On Tue, 24 Oct 2006 19:00:55 +0000 (UTC), AF <noemail at noemail.com>
wrote:
>Thanks for the code. I also implemented a simple win app using the
>main() function (see below file swapp.d).
> While I preffer this simpler form, what I need to know if I will miss
>some functionality specific to the WinMain paradigm. File compilation
>uses the -L/exet:nt/su:windows:4.0 parameter.
>
>Thanks in advance.
>
> AF
>
>-------------file swapp.d-------
>import std.c.windows.windows;
>
>HINSTANCE hInstance;
>
>int main(char[][] args) {
> hInstance = GetModuleHandleA(null); //obtain the hInstance
>parameter
> MessageBoxA(null,"Message text","Message title",MB_OK);
> return 0;
>}
>
>-------------end file swapp.d-----------
Do you know how to access nCmdShow param? User may set the initial
state of the app's window (maximized, etc.) in a shortcut to your app
and you'd better handle this properly.
there is also a rather hackish way to use WinMain without the function
pointer:
modwin.d:
extern(Windows) int winMain(HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
// or you could try extern(C) to hack the D mangling :))
extern(Windows) export int WinMain(HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR lpCmdLine,int nCmdShow)
{
...
result = winMain(hInstance, hPrevInstance,
lpCmdLine,nCmdShow);
}
appwin.d:
import modwin.d
extern(Windows) int winMain(HINSTANCE hInstance, HINSTANCE
hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
...
}
Well, that's insane...
BTW, why methods with external linkage defined in mixins use D
mangling? Is it a bug or feature?
More information about the Digitalmars-d-learn
mailing list