【发布时间】:2017-02-08 13:27:59
【问题描述】:
我正在尝试使用 CreateProcess(...) 启动进程 calc.exe。
在构建解决方案时,我收到错误:
'STARTUPINFO': undeclared identifier
我不明白为什么。
该错误仅在构建解决方案并且变量看起来已定义时出现。
在变量上按 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;
}
【问题讨论】:
-
使用
/showIncludescl 选项查看实际包含的文件。检查该文件,其中定义了STARTUPINFO。看看这是在某些#if块中定义的。检查你是否进入这个街区 -
阅读 MSDN 页面 STARTUPINFO
-
@ryyker - 那又怎样?
-
@RbMm - 它描述了了解如何使用 STARTUPINFO 结构所需的一切。除此之外,您已经在#defines 上提供了提示。
-
@ryyker - 从中得到什么?但是已经在
#include "stdafx.h"中查看了该错误不是第一个干杯和hth。 - 阿尔夫在这里。 msdn 这里无关
标签: c++ c winapi createprocess