c++ - 代码是C还是C++?

标签 c++ c compiler-construction

我知道下面的代码曾经是 C 语言,但是,我在 Visual Studio 2008 中将其编写为 C++ 程序,并且运行良好(保存为 C++)。但是,该程序是 C 代码,对吗? (或者是吗?)。

因此,当我尝试在 Visual Studio 中将其编译为 C 时(转到 -> 文件属性 -> c/c++ -> 高级 -> 编译为 -> 将其更改为“编译为 C 代码”),然后我得到很多错误,其中最主要的是它无法识别 LPSTR 类型。所以,我想我的问题是:它是 C 还是 C++ 代码,如果是 C,为什么当我将其更改为编译 C 代码时它不起作用?

#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <strsafe.h>
#include <direct.h>
#include <string.h>
#include <conio.h>

int main(VOID)
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    //allocate memory
    ZeroMemory(&si, sizeof(si));
    si.cb = sizeof(si);
    ZeroMemory(&pi, sizeof(pi));


    //create child process
    if (!CreateProcess(NULL,
                L"C:\\Windows\\Notepad.exe",
                NULL,
                NULL,
                FALSE,
                0,
                NULL,
                NULL,
                &si,
                &pi))
    {
        fprintf(stderr, "create process failed");

        return -1;
    }

    //parent waits for child to complete
    WaitForSingleObject(pi.hProcess, INFINITE);

    printf("Child Complete");

    //close handle
    CloseHandle(pi.hProcess);
    CloseHandle(pi.hthread);

}  

最佳答案

它可以像 C 一样干净地编译。唯一的错误是由 CloseHandle(pi.hthread) 触发的,因为它不是 PROCESS_INFORMATION 的成员。您正在寻找 hThread(大写 T)。

关于c++ - 代码是C还是C++?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10054349/

相关文章:

c++ - 如何正确地从nalgebra::Matrix转换为Eigen::MatrixXf?

python - distutils.core 与带有 C++ 扩展的 setuptools

c - c语言中sizeof和strlen的区别

c - 是否可以将 zip 文件视为 apache 中的 documentRoot?

compiler-construction - 如何为 Erlang VM 编译

javascript - 在静态(词法)作用域中,变量/声明标识符何时绑定(bind)?

c++ - 在 Windows 中编写引用 HDF5 的 CMakeLists 的正确方法

c++ - 只要不是永远等待,就可以在 DllMain (PROCESS_DETATCH) 中等待吗?

c - main() 递归的不可预测的输出

haskell - 无法在 LLVM OrcJIT 中跨模块访问符号