Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

argc, argv from WinMain??

986 views
Skip to first unread message

Toby Sharp

unread,
Mar 31, 1998, 3:00:00 AM3/31/98
to

Can anyone tell me how to get the classic C command line arguments (argc,
argv) from a Windows application, whose entry point is the WinMain (or
AfxWinMain) function?

I don't want to have to write code for MFC CCommandLine functions because
the code already exists; I just need the argc, argv parameters as given by
the user.


Cheers,
Toby.

Jeff Andrews

unread,
Apr 1, 1998, 3:00:00 AM4/1/98
to

There are global variables available from WinMain, AfxWinMain,
ordinary main, Bangor Maine, or anywhere at all:

__argc - the number of command-line arguments entered.

__argv (__targv for the international version) - an array of
null-terminated character strings which holds as many entries as there
are command-line arguments entered.

In case it's hard to read, those are double leading-underscores.

Regards,
= Jeff Andrews =
andr...@perkin-elmer.com.no-spam
(you know which part to remove to email me...)

------------------------------------------------

Natty...@altavista.net

unread,
Apr 1, 1998, 3:00:00 AM4/1/98
to

In article <34E691D56386D0118D53006008557C721DBEEA@ntcomsrv>,
"Toby Sharp" <toby....@aran.co.uk> wrote:

With BC++ you can use _argv and _argc even in a win app.
If this doesn't fix your prob you can issue a call to GetCommandLine which is
not an mfc but a simple Win API function, so you don't need to re-target your
project.

>
> Can anyone tell me how to get the classic C command line arguments (argc,
> argv) from a Windows application, whose entry point is the WinMain (or
> AfxWinMain) function?
>
> I don't want to have to write code for MFC CCommandLine functions because
> the code already exists; I just need the argc, argv parameters as given by
> the user.
>
> Cheers,
> Toby.
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading

Gudmund Thorgeirsson

unread,
Apr 3, 1998, 3:00:00 AM4/3/98
to

I copied these lines from MSVC++ 5.0 help. I think this is what you need:

CWinApp::m_lpCmdLine
Remarks
Corresponds to the lpCmdLine parameter passed by Windows to WinMain. Points
to a null-terminated string that specifies the command line for the
application. Use m_lpCmdLine to access any command-line arguments the user
entered when the application was started. m_lpCmdLine is a public variable
of type LPSTR.

Good luck!

Toby Sharp wrote in message

B. Gage Renzi

unread,
Apr 3, 1998, 3:00:00 AM4/3/98
to

Don't know if I've missed earlier replies in this thread, but you can use
the global variables __argc and __argv (that's 2 underscores in front)

---------------------------------------------------
<INSERT STD DISCLAIMER HERE>
---------------------------------------------------
B. Gage Renzi
bre...@nospam.lsumc.edu
Programmer In A Box
LSU Medical Center
Dept of Cell Biology & Anatomy
New Orleans, Louisiana
---------------------------------------------------


Steve Quick

unread,
Apr 3, 1998, 3:00:00 AM4/3/98
to

Actually m_lpCmdLine only gives you the arguments of the command line. If
command line is
"wordpad readme.txt", m_lpCmdLine = "readme.txt".

To get entire command line use GetCommandLine();

Gudmund Thorgeirsson wrote in message
<6g2tpp$jde$1...@cenews.ehv.ce.philips.com>...

0 new messages