From: Daniel P. <da...@pr...> - 2008-01-23 18:22:42
|
Grant Edwards wrote: > So a windows _executable_ is either a windows program which > can't have a stdin/stdout/stderr even when started from a > console, or a console program which _must_ have a > stdin/stdout/stderr even it never uses them? The problem actually lies with the Windows SDK, which (by convention, but very entrenched convention) uses an entrypoint called WinMain() instead of the standard C main(). One of the arguments to WinMain() is a HINSTANCE handle to your application, which you will need if you create any windows (since the OS needs to know which process owns the given windows). Since WinMain() and main() define different arguments, only one or the other gets called at startup, depending on the EXE -- (and that's where my knowledge of how Windows works gets fuzzy). Here's a link: http://msdn2.microsoft.com/en-us/library/ms633559(VS.85).aspx So... why can't you get the HINSTANCE some other way? I don't know, but I've never seen an example of it being done. I suppose with some deep C & Win32 wizardry it might be possible to build an executable that bootstraps differently depending on how it was invoked, but I've yet to see a program that does that. Probably an easier solution would be to replace all your stdout/stderr writes with something like the logging module. - Daniel. |