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

x
?
Solved

MFC _tmain  passing parameters

Posted on 2006-10-31
2
Medium Priority
?
1,558 Views
Last Modified: 2008-01-09
Hello,

Can someone write a short pseudo code to pass a string parameter to a MFC console application that supports MFC?  I am trying to pass a string to the _tmain function.  

int   _tmain(int argc, TCHAR* envp[])

thanks in advance....

regards,

Ken
0
Comment
Question by:kenhoppe
2 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 17842464
What do you ask: how to handle parameters in this application, or how to call it?
To call application type in the Command prompt:

your_app_file.exe parameter

Other ways are: to write batch file, create shortcut, add command line arguments to VC++ project properties from running from VC++ IDE.

Inside of application:

int   _tmain(int argc, TCHAR* envp[])
{
    if ( argc > 0 )
    {
          // envp[0] points to _T("parameter") string
    }
}

If you want tu run this program form another program, use CreateProcess function. Parameters should be passed using lpCommandLine functionparameter:
http://windowssdk.msdn.microsoft.com/en-us/library/ms682512.aspx
Replace LPTSTR szCmdline=_tcsdup(TEXT("MyChildProcess")) with LPTSTR szCmdline=_tcsdup(TEXT("MyChildProcess parameter"));
0
 
LVL 18

Accepted Solution

by:
Jose Parrot earned 500 total points
ID: 17842621
Hi,

Comparing to standard console c program
    int main( int argc, char *argv[ ], char *envp[ ] )
we have the equivalent syntax in c console application supporting MFC
    int __cdecl _tmain(int argc, _TCHAR **argv, _TCHAR **envp)
Another format (in essence it is the same, also supporting MFC)
    int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
    {
       if (argc == 1) // argv[0] is the application self name
       {
            show message "There is no arguments"
       }
       if (argc == 2)
       {
            show argument argv[1]
       }

If the symbol _UNICODE is defined for your program, TCHAR is defined as type wchar_t, a 16-bit character type; otherwise, it is defined as char, the normal 8-bit character type.

You can use the CString type, which is based on the TCHAR data type.
Under Unicode, then, CString objects are composed of 16-bit characters. Without Unicode, they are composed of 8-bit char type.

Jose

0

Featured Post

Industry Leaders: 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

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Loops Section Overview

834 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