windows 如何克服 mmsystem.h 引发的错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/540337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:57:21  来源:igfitidea点击:

How to Overcome Errors Thrown by mmsystem.h

c++windowsvisual-studio-2005

提问by Anton Gogolev

I am not able to get out of these simple bugs, but would be great full if some one could answer to weed out from these errors. I included windows.h and some other necessary headers but couldn't able get out of it.

我无法摆脱这些简单的错误,但如果有人能回答从这些错误中剔除,那就太好了。我包含了 windows.h 和其他一些必要的标题,但无法摆脱它。

Snippet of errors:

错误片段:

error C2146: syntax error : missing ';' before identifier 'MMVERSION' 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2143: syntax error : missing ';' before '*' 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2146: syntax error : missing ';' before identifier 'ms' 
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Thanks In Advance

提前致谢

回答by Max Lybbert

To expand on Anton's answer: windows.h #defines UINTto be unsigned int. That's a C macro define, not a typedef. If you #include windows.hbefore you #include mmsystem.hthe line he points to will be read as:

扩展安东的答案: windows.h #defines UINTto be unsigned int。那是一个 C 宏定义,而不是一个typedef. 如果你#include windows.h在你之前#include mmsystem.h,他指向的那条线将被读作:

typedef unsigned int MMVERSION;

However, if you do it the wrong way 'round, then UINT will expand to nothing, and that line will become:

但是,如果您以错误的方式进行操作,则 UINT 将扩展为无,该行将变为:

typedef MMVERSION;

That isn't valid C++ and you will get a parse error. Which is exactly what you're getting.

这不是有效的 C++,你会得到一个解析错误。这正是你得到的。

回答by Anton Gogolev

Look in mmsystem.h, lines 112 and 113:

查看mmsystem.h第 112 和 113 行:

#ifdef _WIN32
typedef UINT        MMVERSION;  /* major (high byte), minor (low byte) */

So be sure to include windows.hbefor including mmsystem.h, and if it does not help, try #defineing _WIN32manually.

所以一定要包括windows.hbefor包括mmsystem.h,如果没有帮助,尝试#define荷兰国际集团_WIN32手动。