2
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++.

Paul R
  • 208,748
  • 37
  • 389
  • 560
  • describe what exactly what you want to do and what you've tried. – Karoly Horvath Mar 09 '15 at 08:05
  • 1
    `LPCTSTR` is a macro defined as either `const char *` or `const wchar_t *`. You can get that from either `std::string` or `std::wstring`, which means you don't have to "combine" anything, just stick to `std::string` or `std::wstring`, and get a C-string pointer when needed. – Some programmer dude Mar 09 '15 at 08:07

1 Answers1

3

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, /* ... */);
Henrik
  • 23,186
  • 6
  • 42
  • 92