Solved

How to get argc/argv in CWinApp?

Posted on 1998-10-19
1
2,794 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

738 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