CreateProcessW 中出错:无法从“STARTUPINFO”转换参数 9到“LPSTARTUPINFO”
我知道 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您有两个
startup_info
。在caller()
中,它是一个STARTUPINFO
(不是指针)。在cp()
中,它是一个STARTUPINFO*&
(对指针的引用)。为什么?这很可能是无意的。我期望:
在生产代码中,我避免使用
p
指针前缀,但我在这里使用它来消除您拥有的两个startup_info
的歧义。You've got two
startup_info
's. Incaller()
, it's aSTARTUPINFO
(not a pointer). Incp()
, it's aSTARTUPINFO*&
(reference to a pointer). Why? It's most likely unintentional.I'd expect:
In production code, I avoid
p
prefixes for pointers but I've used it here to disambiguate the twostartup_info
's which you had.