🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3295

Re: Are all Windows programs ill-formed?

#3295
From: Jerry Coffin
Date: Tue, 06 Feb 1996 19:36
73 lines
3806 bytes
Claude Quezel <Claude.Quezel@gci.ulaval.ca> wrote:

>Could window's main be simply like this:

>int main(int argc, char *argv[]) {
>     // do some stuff
>     return WinMain(// stuff here);
>}

No.  This doesn't seem to accomplish anything.  First of all, it still
requires that the user's code have WinMain defined, which is exactly
what was being avoided to start with.  In addition, at least without
changes in the startup code, you can define main anyway you want to, and
it'll make no difference at all because it'll never get called.  If you
wanted to allow code that used main to compile, you could add something
like the following to the standard library:

extern int __argc;
extern char *__argv[];

int WinMain(/* arguments WinMain receives */) {
	return main(__argc, __argv);
}

However, this really won't buy you much WRT most Windows programs: the
basic structure of a normal Windows program, the header it includes, the
functions it needs to use, etc., prevent the normal Windows environment
from being a legal hosted implementation.  (E.g. stdin/stdout/stderr are
missing...)  OTOH, if we simply view a Windows program as running in a
freestanding environment, I don't see any obvious violations of the
standard, even though it's highly doubtful that this is what the
committee had in mind when they included freestanding implementions in
the standard.

IMO, a reasonable solution to the situation would be a bit of
modification in both Windows and the standard.  IMO, a slightly more
restrictive version of Jonathon De Boyne Pollard's proposal might work
best: require that any form of main the takes arguments have argc and
argv as the first two (with whatever names the programmer desires of
course) with other, implementation defined arguments allowed aftewards.
In this case, a suitable version for a Win32 program might be:

int main(int argc, char **argv, HINSTANCE hInst, int nCmdShow)

By requiring that argc/argv always be passed as the first to parameters,
conforming programs that expect those as the first two parameters are
supported in the extended environments, whether Windows or otherwise.
In this case, the entry point for a Win32 program might be:

#include <windows.h>
extern int __argc;
extern char *__argv[];

WinMain(HINSTANCE Inst, HINSTANCE PrevInst, char *CmdLine, int nCmdShow)
{
// under Win32, hPrevInst is included only for compatibility: it will
// alway be NULL, so we'll ignore it.  Likewise, since we're passing
// argc/argv, there's little reason to worry about the unprocessed
// command line.

	return main(__argc, __argv, Inst, nCmdShow);
}

This would, of course, require that main be called in such a way that if
some arguments were ignored that it wouldn't cause a catastrophe.  Given
the current requirement that main be able to ignore argc and argv, this
shouldn't require anything new.


[ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy is
  summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Technical Details
Message-ID: <4f8a3a$sgq@natasha.rmii.com>
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!train7!clamage
References: <AE5J83na99@qsar.chem.msu.su> <9602010236.26117@mulga.cs.mu.OZ.AU> <9602021032.AA05302@lts.sel.alcatel.de> <4eucsq$qn@athena.ulaval.ca>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!engnews1.Eng.Sun.COM!train7!clamage
From: jcoffin@rmii.com (Jerry Coffin)
Newsgroups: comp.std.c++
Subject: Re: Are all Windows programs ill-formed?
Date: 6 Feb 1996 19:36:34 GMT
Organization: TAEUS
Approved: clamage@eng.sun.com (comp.std.c++)
Message-ID: <4f8a3a$sgq@natasha.rmii.com>
References: <AE5J83na99@qsar.chem.msu.su> <9602010236.26117@mulga.cs.mu.OZ.AU> <9602021032.AA05302@lts.sel.alcatel.de> <4eucsq$qn@athena.ulaval.ca>
NNTP-Posting-Host: train7.eng.sun.com
Content-Type: text
X-Nntp-Posting-Host: slip22157.rmii.com
X-Newsreader: Forte Free Agent 1.0.82
Content-Length: 2847
X-Lines: 68
Originator: clamage@train7