我正試圖用CreateProcess(...)
啓動進程calc.exe。
當我建立我收到了錯誤的解決方案:
'STARTUPINFO':未聲明的標識符由於構建錯誤而無法使用CreateProcess:'STARTUPINFO':未聲明的標識符
我不理解爲什麼。
該錯誤僅在構建解決方案和定義變量時出現。
當它出現的變量按F12:
也許這關係到#ifdef UNICODE
?
全碼:
// CppConsoleApp.cpp : Defines the entry point for the console application.
//
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "stdafx.h"
int main()
{
STARTUPINFO info;
PROCESS_INFORMATION processInfo;
ZeroMemory(&info, sizeof(info));
info.cb = sizeof(info);
ZeroMemory(&processInfo, sizeof(processInfo));
LPCWSTR path = L"C:\\Windows\\System32\\calc.exe";
if (!CreateProcess(path, NULL, NULL, NULL, TRUE, 0, NULL, NULL, &info, &processInfo))
{
printf("CreateProcess failed (%d).\n", GetLastError());
}
WaitForSingleObject(processInfo.hProcess, INFINITE);
CloseHandle(processInfo.hProcess);
CloseHandle(processInfo.hThread);
return 0;
}
使用'/ showIncludes'cl選項來查看,實際包含哪些文件。檢查該文件,其中包含「STARTUPINFO」。看,這是在一些'#if'塊中定義的。檢查你是否在這個模塊 – RbMm
閱讀MSDN頁面_ [STARTUPINFO](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v = vs.85).aspx)_ – ryyker
@ryyker - 那又如何? – RbMm