Solved

How to get argc/argv in CWinApp?

Posted on 1998-10-19
1
2,782 Views
Last Modified: 2013-11-20
I would like to be able to get command line options in
argc & argv format in my InitInstance() call without
having to parse through the m_lpCmdLine string myself.
Is there an easy way to do this?
Thanks.
0
Comment
Question by:bwilhelm
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1323527
Use __argv and __argc (double underline precedes the name) :

(begin quote)
Windows-based and Win32-based application use WinMain() as the entry point. WinMain() has the lpszCmdLine parameter for the command line arguments, but this parameter does not include the program name. However, you can

 still get to the program name through the variable __argv.

In a 32-bit application you can just reference __argv directly. It is declared in stdlib.h
In a 16-bit application, __argv is not declared and you will need to declare it. Include the following declaration in your source or header file:

#ifdef __cplusplus extern "C"  #endif extern char ** __argv;

To test this out, you can view __argv[0] by including the following line in your application:


   MessageBox( NULL, __argv[0], "__argv[0]", MB_OK );

NOTE: argv[0] will contain a pointer to the program name as it was executed from the command line or Program Manager: either qualified or unqualified.
(end quote)

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 95
viewing source code from eclipse 13 110
Use of condition with 'serial' in ansible 2 86
Not needed 13 129
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question