I am new to programming. I want simply create a process , but it always fail.
This is the code.
#include <Windows.h>
#include <atlconv.h>
#include <iostream>
wchar_t* atw(const char* oc)
{
USES_CONVERSION;
return A2W(oc);
}
int main() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory(&si, sizeof(si));
ZeroMemory(&pi, sizeof(pi));
if (CreateProcess(
NULL,
atw("E:\\AFolder\\AProgram.exe"),
NULL,
NULL,
false,
NULL,
NULL,
atw("E:\\AFolder"),
&si,
&pi
))
{
//do something
}
else {
//do something
}
...
}
"AProgram.exe" and "AFolder" are just symbols , I am sure they exist and can run.
Also, my native language is not English, plesae ignore some possible language mistakes and cultural conflict
CodePudding user response:
I'm afraid than atw() return a dangling pointer.
check A2W implementation details and warnings from the compiler.
your usage of A2W is wrong.
possible solutions :
std::wstring atw(const char* oc)
{
USES_CONVERSION;
return A2W(oc);
}
or use A2W directly in main