[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to get argc/argv in CWinApp?

Posted on 1998-10-19
1
Medium Priority
?
2,904 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 400 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

872 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