Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Parameter (e.g. testprogram.exe parameter1)

Status
Not open for further replies.

slimtimbodin

Programmer
Nov 16, 2001
11
How do you set up a VC++ Dialog based program, that is created using the VC++ application wizard, to receive an incoming parameter. Example: testprogram.exe parameter1 or if I wanted to pass a textfile to the program - testprogram.exe textfile.txt

I have checked all my newbie C++ books and I can't figure out how to do this.

Thank you in advance.
 
I believe this is done in the main method:

void main(parameters here)
{
// code here
}

you might want to look into the function of parameters in the main method. Sorry I couldn't try this out before writting.

Good Luck,
Mike Take Care,
Mike
 
Thanks Mike.

I think that is the way you would do it with a console application but with a Dialog application created with the VC++ application wizard there is no main. So since there is no main, I wonder where the parameter would go????

Also with a simple console application created with VC++ it makes main like this: int main(int argc, char* argv[]) so I would guess you would add a third argument to that to make it work?????

Tim
 
Just a side note... in the program settings you can set command line args as well so you dont need to rewrite the code for debug

matt
 
I found this in the help section and I was successful with my project:

---------------------------
If you write your application in Microsoft® Foundation Classes (MFC), you should create a command-line class that inherits from the CCommandLineInfo class and override the ParseParam method. During your application's InitInstance method, your application should create an instance of the command-line object. Your application should then call the ParseCommandLine method of the CWinApp class from which your application inherits and pass the command-line object. The ParseCommandLine method then parses and passes each argument in the command line to the ParseParam method that you implement. After ParseParam fills the command-line object, your application passes the command-line object to the ProcessShellCommand method of the CWinApp class. ProcessShellCommand then handles the command-line arguments and flags to perform the indicated operation.

The ParseParam method that you implement should evaluate the arguments of the command line and process them according to whether they are specific flags or functions or the final argument of the command line. Your ParseParam method should create static variables that will store the most recently passed flag argument and a boolean value indicating whether or not ParseCommandLine passed the command to begin recording. If your ParseParam method receives an argument and determines that the static flag variable holds a function flag, ParseParam should evaluate the argument according to the operation specified. If the argument specifies to start recording, ParseParam should set the static boolean value for recording. If the argument specifies to end recording, ParseParam should send a command to stop recording. If your ParseParam method receives an argument and determines that the static flag variable holds a channel flag, ParseParam should evaluate the argument and send commands to the remote control to tune the VCR. If your ParseParam method determines that it received the final argument and that its static boolean value was set for recording, ParseParam should send a command to start recording.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top