Error in CreateProcessW: cannot convert parameter 9 from 'STARTUPINFO' to 'LPSTARTUPINFO &'
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 b开发者_开发问答y 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
}
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.
精彩评论