Solved

How to get argc/argv in CWinApp?

Posted on 1998-10-19
1
2,695 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now