Ramon Larodo
Ramon Larodo

Reputation: 95

C++ LPCTSTR how to pass command line args to child process

LPCTSTR applicationName = NUL // NULL => module name from command line
string argument1 = "something";
string argument2 = "anotherthing";
LPTSTR  commandLine = "childpath\\child.exe";
success = CreateProcess(
applicationName,
commandLine,
processSecurityAttrs,etc...)

What I am trying to do here is trying to pass parent's command line args to child. But it is LPTSTR, I do not know how to combine string and LPTSTR type and pass it to the child. It gives me type def. error. I use Visual Studio 2013 and C++.

Upvotes: 2

Views: 1379

Answers (1)

Henrik
Henrik

Reputation: 23324

According to the documentation:

The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.

Example from the docs:

LPTSTR szCmdline[] = _tcsdup(TEXT("\"C:\\Program Files\\MyApp\" -L -S"));
CreateProcess(NULL, szCmdline, /* ... */);

Upvotes: 3

Related Questions