CreateProcessW出错:无法将参数9从“STARTUPINFO”转换为“LPSTARTUPINFO&”

时间:2011-09-27 07:39:26

标签: c++ windows createprocess

我了解startup_info是指向STARTUPINFO结构

的指针

我有一个函数,我将startup_info通过引用传递给它。所以我们可以说我通过引用传递指针

void cp(....., LPSTARTUPINFO & startup_info) {
  CreateProcessW(....., startup_info);
}

让我们假设我在函数caller()

中调用函数cp
void caller() {
  STARTUPINFO startup_info; 
  cp(....., startup_info); // error occurs here, I cannot convert 'STARTUPINFO' to 'LPSTARTUPINFO &'
}

它会给我错误信息:CreateProcessW出错:无法将参数9从'STARTUPINFO'转换为'LPSTARTUPINFO&'

但是由于statup_info是一个指针,我应该可以将它传递给函数cp吗?

编辑: 感谢您的建议,但以下内容适用于我: LPSTARTUPINFO是指向STARTUPINFO结构

的指针

所以我改为

void cp(....., LPSTARTUPINFO startup_info_ptr) {
      CreateProcessW(....., startup_info_ptr); // pass in pointer of startup_info
}

void caller() {
      STARTUPINFO startup_info; 
      cp(....., &startup_info); // passing the address of startup_info
}

1 个答案:

答案 0 :(得分:2)

你有两个startup_info。在caller()中,它是STARTUPINFO(不是指针)。在cp()中,它是STARTUPINFO*&(对指针的引用)。为什么?这很可能是无意的。

我希望:

void cp(....., STARTUPINFO* pStartup_info) {
  CreateProcessW(....., pStartup_info);
}
void caller() {
  STARTUPINFO startup_info; 
  cp(....., &startup_info);
}

在生产代码中,我避免使用p前缀作为指针,但我在这里使用它来消除你所拥有的两个startup_info的歧义。