error C2146: 语法错误: 缺少“;”(在标识符“WINAPI”的前面) 及 “error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int” 解决方案

来源:互联网 发布:热力地图js 编辑:程序博客网 时间:2024/06/08 15:40

在VS里字定义了一个工程,添加了一个CPP和H,编译时出现了以下奇怪的错误:

1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(30): error C2146: 语法错误: 缺少“;”(在标识符“WINAPI”的前面)
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(30): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(30): error C2146: 语法错误: 缺少“;”(在标识符“CreateToolhelp32Snapshot”的前面)
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(30): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(31): error C2065: “DWORD”: 未声明的标识符
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(31): error C2146: 语法错误: 缺少“)”(在标识符“dwFlags”的前面)
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(31): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(33): error C2059: 语法错误:“)”
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(64): error C2146: 语法错误: 缺少“;”(在标识符“dwSize”的前面)
1>c:\program files (x86)\microsoft sdks\windows\v7.0a\include\tlhelp32.h(64): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int


像这样的问题一般一般是由于头文件包含引起的错误。

在CPP的最前面包含 windows.h问题就解决了。为什么会想到这一点呢?同样的CPP和H,在另一个工程里可用,而在这里不能用。对比发现可用的那个工程里,该CPP包含了STDAFX.H,而STDAFX.H里包含了window.h。


话说windows.h 怎么就那么重要呢,不包含,还不让编译通过。打开windows.h,里面全部是头文件包含。VS已经帮我们定义好了在window平台上开发程序所需的头文件和顺序。

以后进行windows编程的时候记得包含就行了。


再来看下stdafx.h,包含可是很标准的哟

// stdafx.h : 标准系统包含文件的包含文件,// 或是经常使用但不常更改的// 特定于项目的包含文件//#pragma once#include "targetver.h"#include <stdio.h>#include <tchar.h>// TODO: 在此处引用程序需要的其他头文件#include <windows.h>

这个顺序要记住啦。。。




2 0
原创粉丝点击