Solved

How to get argc/argv in CWinApp?

Posted on 1998-10-19
1
2,766 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
not able to insert into temp table 68 169
Define unique primary key 9 95
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 101
dog bark java program 15 109
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

840 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