> > Even when launched with double-clicking?
> > You should not rely on args[0] anyway, because applications that launch your app could put anything in args[0] they want.
> really? args[1] might be anything, specified at the command-line or whatever, but surely args[0] is the command invoked to get the app running?
Look at the following code. The whole command line can be customised by the parent app.
<code>
static int create_process(const string& exe_name, const string& _cmd_line, bool wait)
{
char cmd_line[256];
strcpy(cmd_line, ("\"" + exe_name + "\" " + _cmd_line).c_str());
STARTUPINFO si;
memset(&si, 0, sizeof(STARTUPINFO));
si.cb = sizeof(STARTUPINFO);
PROCESS_INFORMATION pi;
int error = !CreateProcess(exe_name.c_str(), cmd_line, NULL, NULL, false, CREATE_DEFAULT_ERROR_MODE, NULL, NULL, &si, &pi);
if (!error && wait)
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return error;
}
</code>