CreateProcessW 中出错:无法从“STARTUPINFO”转换参数 9到“LPSTARTUPINFO”

发布于 2024-12-06 19:51:51 字数 999 浏览 0 评论 0原文

我知道 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 &'
}

它会给我错误消息:Error in 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
}

I understand that startup_info is a pointer to a STARTUPINFO structure

I have a function which I pass startup_info by reference into it. So we can say that I am passing a pointer by reference

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

Let us assume that I call function cp in this function caller()

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

It will give me error message: Error in CreateProcessW: cannot convert parameter 9 from 'STARTUPINFO' to 'LPSTARTUPINFO &'

But since statup_info is a pointer, I should be able to pass this into function cp right?

EDIT:
Thank you for your advices,but the following works for me:
LPSTARTUPINFO is a pointer to STARTUPINFO structure

So I change to

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
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一指流沙 2024-12-13 19:51:51

您有两个 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 的歧义。

You've got two startup_info's. In caller(), it's a STARTUPINFO (not a pointer). In cp(), it's a STARTUPINFO*& (reference to a pointer). Why? It's most likely unintentional.

I'd expect:

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

In production code, I avoid p prefixes for pointers but I've used it here to disambiguate the two startup_info's which you had.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文