October 24, 2006
Thanks, but I think simpler than that is almost impossible: all I did was to cut & paste...
October 24, 2006
Thanks for the hint. It was the hInstance I was missing up without WinMain.

I think the official recommandation (and example) should be with
main() not with WinMain(). For all old Win programmers, WinMain
could be obvious. However, for a novice it seems pretty confusing
to change paradigm according to OS and maybe bracket everything
with version(){}.

My opinion, however.

Thanks for the submitted code (with function pointers) and for
overall help. I will give it a try.

AF
October 24, 2006
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-----------
October 24, 2006
On Tue, 24 Oct 2006 19:00:55 +0000 (UTC), AF <noemail@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?


October 25, 2006
 No, I don't know how to access the nCmdShow parameter.
 Is there any possibility?

 On the other hand, about linkage and magling, I simply do not know.

 Thanks for the new code, I will give it a try.
October 26, 2006
On Wed, 25 Oct 2006 05:50:01 +0000 (UTC), AF <noemail@noemail.com>
wrote:

> No, I don't know how to access the nCmdShow parameter.
> Is there any possibility?
>
> On the other hand, about linkage and magling, I simply do not know.
>
> Thanks for the new code, I will give it a try.

Sorry, I failed to figure out how to access nCmdShow from main(). Maybe somebody else could help? I'm sure Walter knows the answer.
November 05, 2006
Max Samuha wrote:
> On Wed, 25 Oct 2006 05:50:01 +0000 (UTC), AF <noemail@noemail.com>
> wrote:
> Sorry, I failed to figure out how to access nCmdShow from main().
> Maybe somebody else could help? I'm sure Walter knows the answer.   

You could use Windows API GetStartupInfo() (http://windowssdk.msdn.microsoft.com/library/ms683230)
I believe STARTUPINFO.wShowWindow is what you need.

-- 
serg.
November 05, 2006
Thanks. I will do some further reading on that API.

I wanted also to know if the main() version loses some functionality
at the gc level, comparatively with the WinMain() Walter-provided
boilerplate, but I hope the question is not critical.

Thanks again.

AF

1 2
Next ›   Last »