【问题标题】:C++ LPCTSTR how to pass command line args to child processC ++ LPCTSTR如何将命令行参数传递给子进程
【发布时间】:2015-03-09 08:02:40
【问题描述】:
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...)

我在这里尝试做的是尝试将父母的命令行参数传递给孩子。但它是LPTSTR,我不知道如何组合stringLPTSTR类型并传递给孩子。它给了我类型def。错误。我使用 Visual Studio 2013 和 C++。

【问题讨论】:

  • 具体描述您想要做什么以及您尝试过的内容。
  • LPCTSTR 是一个定义为const char *const wchar_t * 的宏。您可以从std::stringstd::wstring 获得它,这意味着您不必“组合”任何东西,只需坚持std::stringstd::wstring,并在需要时获取一个C 字符串指针。跨度>

标签: c++ windows command-line pipe lptstr


【解决方案1】:

根据documentation

此函数的 Unicode 版本 CreateProcessW 可以修改此字符串的内容。因此,此参数不能是指向只读内存的指针(例如 const 变量或文字字符串)。如果此参数是一个常量字符串,该函数可能会导致访问冲突。

文档中的示例:

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

【讨论】:

    猜你喜欢
    • 2016-03-08
    • 2013-07-12
    • 2011-12-13
    • 2010-10-04
    • 2013-12-23
    • 2020-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多