繁体   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