代码是C还是C++?

Fav*_*ksd 0 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);

}  
Run Code Online (Sandbox Code Playgroud)

cni*_*tar 6

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