Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

How to get command-line arguments in Windows application?

Status
Not open for further replies.

Maayan

Computer
Nov 7, 2004
2
I want to parse command-line arguments of windows application. The windows application main entry point is _tWinMain (or WinMain).
There is no indication of the argv/argc parameters. The reason I need them is because I want to use the getopt function.
Therefore, I need one of 2:
1. Get the argv/argc arguments and use getopt.
2. Use some utility function of windows that does the same.

Best regards,
Erez
 
Replies continue below

Recommended for you


I am pasting below (From MSDN) the description of WinMain function.As given below lpCmdLine contains the arguments passed to it.


WinMain
The WinMain function is called by the system as the initial entry point for a Win32-based application.

int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
);
Parameters
hInstance
[in] Handle to the current instance of the application.
hPrevInstance
[in] Handle to the previous instance of the application. For a Win32-based application, this parameter is always NULL.
If you need to detect whether another instance already exists, create a uniquely named mutex using the CreateMutex function. CreateMutex will succeed even if the mutex already exists, but the GetLastError function will return ERROR_ALREADY_EXISTS. This indicates that another instance of your application exists, because it created the mutex first.

lpCmdLine
[in] Pointer to a null-terminated string specifying the command line for the application, excluding the program name. To retrieve the entire command line, use the GetCommandLine function.
nCmdShow
[in] Specifies how the window is to be shown. This parameter can be one of the following values.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor