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 cowski 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
Joined
Nov 7, 2004
Messages
2
Location
IL
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
 

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

Back
Top