Where has argv[] gone in WinMain?

  • Thread starter Thread starter Teis Draiby
  • Start date Start date
T

Teis Draiby

In a console VC++ application it is possible to read the argv[1] argument to
retrieve the path of the file that has been drag&dropped onto the executable
file. Likewise I can get the path of the running process by argv[0].

What is the equivalent methods using the Win32 WinMain( ) procedure?

Thank you in advance for your help,
Teis
 
Teis said:
In a console VC++ application it is possible to read the argv[1]
argument to retrieve the path of the file that has been drag&dropped
onto the executable file. Likewise I can get the path of the running
process by argv[0].

What is the equivalent methods using the Win32 WinMain( ) procedure?

GetCommandLine
And for NT an later: CommandLineToArgvW


You can also use MFC to retrive the commandline
(See CCommandLineInfo class)

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
 
Hi Teis,

Teis Draiby said:
In a console VC++ application it is possible to read the argv[1] argument to
retrieve the path of the file that has been drag&dropped onto the executable
file. Likewise I can get the path of the running process by argv[0].

What is the equivalent methods using the Win32 WinMain( ) procedure?

You can call:

char szPath[MAX_PATH];
DWORD cbPath = GetModuleFileName(NULL, szPath, sizeof(szPath)-1);
// now szPath contains the path + filename of your executable

HTH,
SvenC
 
Thanks you for replying Jochen and Sven.
I realize that there are multiple ways to do this.
I discovered that I can simply call the somewhere predefined '__argv[]' and
'__argc' which appears similar to their argv, argc console counterparts.
That seems somewhat easier -is that cheating? Can I expect any issues using
them?

thanks, Teis



(Sven, where is .tfg)



Jochen Kalmbach said:
Teis said:
In a console VC++ application it is possible to read the argv[1]
argument to retrieve the path of the file that has been drag&dropped
onto the executable file. Likewise I can get the path of the running
process by argv[0].

What is the equivalent methods using the Win32 WinMain( ) procedure?

GetCommandLine
And for NT an later: CommandLineToArgvW


You can also use MFC to retrive the commandline
(See CCommandLineInfo class)

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
 
Teis said:
I discovered that I can simply call the somewhere predefined
'__argv[]' and '__argc' which appears similar to their argv, argc
console counterparts. That seems somewhat easier -is that cheating?
Can I expect any issues using them?

Als long as you use the CRT as "Main-Entry-Point" you can use it:

See also: HOWTO: Obtain the Program Name in a Windows-Based Application
http://support.microsoft.com/?kbid=126571

--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
 
Back
Top