簡體   English   中英

由於發生構建錯誤而無法使用CreateProcess:'STARTUPINFO':未聲明的標識符

[英]Can't use CreateProcess because of a build error: 'STARTUPINFO': undeclared identifier

我正在嘗試使用CreateProcess(...)啟動進程calc.exe。
在構建解決方案時,我收到錯誤消息:
'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;
}

您首先需要將#include "stdafx.h" 放在首位

或在項目設置中關閉預編譯頭,以獲取標准C ++的預處理行為。

使用預編譯頭時,所有包含預編譯頭(在您的情況下為"stdafx.h" )的內容都將被忽略。


有一種關於您所處情況的警告,其中包含被忽略。 如果通常要使用預編譯頭,則應找到該警告號並指定應將其視為錯誤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM