简体   繁体   中英

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

I am trying to start the process calc.exe with CreateProcess(...) .
When I am building the solution I received the error:
'STARTUPINFO': undeclared identifier

在此处输入图片说明

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:
在此处输入图片说明

Maybe it related to the #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.

Or turn off precompiled headers in the project settings to get standard C++'s preprocessing behavior.

With precompiled headers everything up to the include of the precompiled header, which in your case is "stdafx.h" , is ignored.


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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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