This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: BUG: winmain GetCommandLine only returning program name and path with no arguments
- From: Dan Kegel <dank at kegel dot com>
- To: mikebarry at gmail dot com, cygwin at cygwin dot com
- Date: Sat, 13 May 2017 08:34:14 -0700
- Subject: Re: BUG: winmain GetCommandLine only returning program name and path with no arguments
- Authentication-results: sourceware.org; auth=none
- References: <CAF_6hF4+jNWuqA-7jSn2=Jqb2X--MDmY0qhbNwtLxBcHwkrxbA@mail.gmail.com>
That same executable behaves properly when built with cl.exe *or* run from cmd.
Only when built with cygwin gcc *and* run from cygwin shell does it
not show the full string,
and bonus, in that case does not set szCmdLine properly?
#include <windows.h>
#include <stdio.h>
int WINAPI
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {
char* text = GetCommandLine();
printf("getcmdline: %p %s\n", text, text);
printf("szCmdLine: %p %s\n", szCmdLine, szCmdLine);
return 0;
}
Built as a.exe by gcc, example.exe by cl
$ ./a.exe x y z
getcmdline: "C:\cygwin64\home\buildbot\a.exe"
szCmdLine:
$ ./example.exe x y z
getcmdline: C:\cygwin64\home\buildbot\example.exe x y z
szCmdLine: x y z
$ cmd
Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.
C:\cygwin64\home\buildbot>a.exe x y z
getcmdline: a.exe x y z
szCmdLine: x y z
C:\cygwin64\home\buildbot>example.exe x y z
example.exe x y z
C:\cygwin64\home\buildbot>getcmdline: example.exe x y z
szCmdLine: x y z
(Incidentally,
http://stackoverflow.com/questions/13871617/winmain-and-main-in-c-extended/13872211
and
http://daviddeley.com/autohotkey/parameters/parameters.htm looks
like informative if one is interested in some nasty details. )
On Sat, May 13, 2017 at 7:30 AM, Mike Barry <mike.barry@gmail.com> wrote:
> Below is a sample program that demonstrates that the GetCommandLine
> function is not returning the command line arguments. I attached
> cygcheck.out.
>
> #include <windows.h>
> #include <stdio.h>
>
> int WINAPI
> WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw) {
> char* text = GetCommandLine();
> printf("getcmdline: %s\n", text);
> return 0;
> }
>
> gcc test_wmain.c -o test
>
> $ ./test hello world
> getcmdline: "C:\cygwin64\home\mbarry\game-repos\greenbeam\src\test.exe"
>
>
> --
> Problem reports: http://cygwin.com/problems.html
> FAQ: http://cygwin.com/faq/
> Documentation: http://cygwin.com/docs.html
> Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple