This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: cygwin 1.5.11: execv doesn't set argv[0] on Windows programs


On Fri, 10 Sep 2004, Dave Korn wrote:

> > -----Original Message-----
> > From: cygwin-owner On Behalf Of Igor Pechtchanski
> > Sent: 10 September 2004 14:57
>
> > On Fri, 10 Sep 2004, Christopher Faylor wrote:
>
> > > There is no such thing as "argv[0]" for a Windows program.  Cygwin
> > > uses CreateProcess to create processes.  CreateProcess does not have
> > > the concept of "argv[0]".  Perhaps Microsoft's exec functions do
> > > something funky that is understood by other msvcrt programs.
> > > Cygwin doesn't do that.
> >
> > Allow me to disagree.  CreateProcess takes two separate arguments: the
> > image to run, and the command line (yes, as one long line).  The
> > actual executable being run is the image parameter, but the value of
> > argv[0] is extracted from the command line one (well, unless the image
> > name is NULL, in which case the image name and argv[0] are the same).
> > That's the value of argv[0] that I meant.
>
>   Allow me to disagree!  The Win32 API specifies precisely the form that
> the entry function of a win32 application must conform to:
>
> int WINAPI WinMain(
>   HINSTANCE hInstance,      // handle to current instance
>   HINSTANCE hPrevInstance,  // handle to previous instance
>   LPSTR lpCmdLine,          // command line
>   int nCmdShow              // show state
> );
>
>   There is no concept of argv in the windows OS itself.  The application
> gets the entire commmand line as one unparsed string.

Fair enough.  Thanks for the clarification.

What I meant was that the first token of the command line was set to the
image name when invoking Windows applications from Cygwin.  So, even if a
Cygwin app sets argv[0] explicitly (which should be incorporated into the
lpCmdLine), that first token would be the same as the image name, and not
what was specified.

>   Now, it may well be the case that most applications link against the
> msvcrt library, which contains an implementation of WinMain that parses
> lpCmdLine into separate tokens, puts them into an array, and then calls
> out to a function named 'main' in the user's app that is linked with the
> library, passing it argc and argv parameters.  But it's fair to point
> out that the argv concept is not part of the OS, it's part of a compiler
> support library; it's not handled by the OS, it's not passed to
> applications, it's not defined in the API, and there are plenty of
> applications that implement their own (or a predefined) WinMain in a
> different fashion and do _not_ tokenize and parse the command line; 99%
> of all MFC apps, for instance.

True, but irrelevant.  My complaint was that the first token of the
command line, as specified by Cygwin's execv(), was ignored in favor of
the image name.
Hope this clarifies things,
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Happiness lies in being privileged to work hard for long hours in doing
whatever you think is worth doing."  -- Dr. Jubal Harshaw

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]