How to obtain BCB running parameters

Source: Internet
Author: User

In this paper, the conversion from C ++ builder research-http://www.ccrun.com/article/go.asp? I = 130 & D = 33h2e2
Anyone who has used C language programming knows that in DOS programming, the number of command line parameters and the strings of each parameter can be obtained through the parameters of the main function, such

Int main (INT argv, char * argv [])
{
...
}

The command line parameters are argc, which are stored in argv [0] ~ In argv [argc-1] Where argv [0] is the name of the executable file (including the path), how does a Windows program get the command line parameter? Anyone who has written Windows programs in C language knows that in windows, the main function winmain () has a parameter lpszcmd, which is the command line parameter. However, we generally do not work in the winmain () function during windows programming. Additionally, lpszcmd is the entire command line. It is not convenient to obtain each parameter. Is there a better way?

If you are using C ++ builder for programming, I would like to congratulate you. Using command line parameters in C ++ builder is very simple. C ++ builder defines three global variables and functions including response line, paramstr (), and paramcount (). With these three variables and functions, you can easily use the command line parameters. First, let's take a look at the definitions of these functions and variables:

Extern package char * cmdline;
Extern package ansistring _ fastcall paramstr (INT index );
Extern package int _ fastcall paramcount (void );

The parameter lpszcmd of cmdline and winmain () is the same, that is, the entire command line parameter. paramcount () is used to obtain the number of command line parameters, but does not include the executable file name, that is equivalent to the argc-1 under DOS, paramster () is used to obtain the value of each command line parameter, paramstr (0) is the executable file name, the actual parameter is paramstr (1 )~ Paramstr (paramcount ()). The following example shows how to use these three function variables.

Place a label on the form to display the total command line parameters. Add a ListBox to display each parameter, and add the following code to the oncreate event of the form:

Label1-> caption = nearline;
For (INT I = 0; I <= paramcount (); I ++)
Listbox1-> items-> Add (paramstr (I ));

Run-> parameters... Modify the command line parameters, and then run the program ...... How is it? Simple enough!

 

The following is the original content of Yao Yin:

The project entry code snippets are as follows:

Winapi winmain (hinstance, hinstance, lpstr lpcmdline, INT)
{
Required line = "-n-v-x yy.exe ";

Paramcount () is not equal to 4, that is, the program running parameter specified here is incorrect. In fact, a parameter of winmain is used in the project entry function.

The lpcmdline is a pointer to a command line parameter. That is to say, before the project runs, the command line parameter is known.

To change the running parameters, select "Run-" parameter-"in the menu, and write"-n-v-x yy.exe "in the space. The value of paramcount () is 4.

 

To pass parameters to the application through code, the available winexec is detailed in the http://msdn.microsoft.com/en-us/library/ms687393

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.