Incorrectly prepared lpCmdLine parameter of WinMain()

Christopher Faylor
Thu Dec 9 15:36:00 GMT 2004

On Thu, Dec 09, 2004 at 12:41:22PM +0100, Pavel Kudrna wrote:
>The caller of WinMain() incorrectly parses the command line if e.g.
>the space is present in the path or filename of the executable.
>The lpCmdLine then contains part of the filename at the beginning.
>/* program.c*/
>#include <windows.h>
>int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, 
>LPSTR lpCmdLine, int nCmdShow )
> MessageBox(NULL, lpCmdLine, "lpCmdLine:", MB_OK );
> return 0;
>$ gcc program.c -mwin32
>$ mv a.exe "a a.exe"
>$ "./a a.exe" "1st parameter" 2nd\ parameter
>Then MessageBox shows that lpCmdLine contains:
>a.exe" "1st parameter" "2nd parameter"
>If program is compiled with -mno-cygwin the bug is not present and 
>lpCmdLine is ok:
>"1st parameter" "2nd parameter"

Sounds like you should be using argv[] rather than lpCmdLine.

Unsubscribe info:
Problem reports:

More information about the Cygwin mailing list