gpt4 book ai didi

c++ - CreateProcessW : cannot convert parameter 9 from 'STARTUPINFO' to 'LPSTARTUPINFO &' 错误

转载 作者:行者123 更新时间:2023-11-28 03:46:16 26 4
gpt4 key购买 nike

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

最佳答案

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

关于c++ - CreateProcessW : cannot convert parameter 9 from 'STARTUPINFO' to 'LPSTARTUPINFO &' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7565691/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com