简体   繁体   English

由于发生构建错误而无法使用CreateProcess:'STARTUPINFO':未声明的标识符

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

I am trying to start the process calc.exe with CreateProcess(...) . 我正在尝试使用CreateProcess(...)启动进程calc.exe。
When I am building the solution I received the error: 在构建解决方案时,我收到错误消息:
'STARTUPINFO': undeclared identifier 'STARTUPINFO':未声明的标识符

在此处输入图片说明

I am not understanding why. 我不明白为什么。
The error is only when building the solution and the variable looks defined. 该错误仅在构建解决方案且变量已定义时发生。
When pressing F12 on the variable it appears as: 在变量上按F12时,它显示为:
在此处输入图片说明

Maybe it related to the #ifdef UNICODE ? 也许与#ifdef UNICODE

Full code: 完整代码:

// 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;
}

You need to put #include "stdafx.h" first of all. 您首先需要将#include "stdafx.h" 放在首位

Or turn off precompiled headers in the project settings to get standard C++'s preprocessing behavior. 或在项目设置中关闭预编译头,以获取标准C ++的预处理行为。

With precompiled headers everything up to the include of the precompiled header, which in your case is "stdafx.h" , is ignored. 使用预编译头时,所有包含预编译头(在您的情况下为"stdafx.h" )的内容都将被忽略。


There is a warning about the situation you have, where includes are ignored. 有一种关于您所处情况的警告,其中包含被忽略。 If you want to use precompiled headers in general, you should find that warning number and specify that it should be treated as an error. 如果通常要使用预编译头,则应找到该警告号并指定应将其视为错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM