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


> -----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.

  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.


    cheers, 
      DaveK
-- 
Can't think of a witty .sigline today....


--
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]