Why does this code return 2, which is ERROR_PATH_NOT_FOUND?
int runCmd()
{
char buff[] = "c:\\windows\\system32\\cmd.exe /c dir";
STARTUPINFOW si;
PROCESS_INFORMATION pi;
SECURITY_ATTRIBUTES sa;
ZeroMemory(&si, sizeof(STARTUPINFOW));
ZeroMemory(&pi, sizeof(PROCESS_INFORMATION));
ZeroMemory(&sa, sizeof(SECURITY_ATTRIBUTES));
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = NULL;
si.cb = sizeof(STARTUPINFOW);
if (!CreateProcessW(NULL, (LPWSTR)buff, NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,&si,&pi)) // failed
{
return GetLastError();
}
return 0;
}
If I use the ANSI functions and structs, this works fine, but when the W suffix is used, it does not work.