它说头文件有问题,mmsystem.h,我不能使用 PlaySound()

It said there's something wrong with the header file, mmsystem.h, i can't use PlaySound()

#include <iostream>
#include <stdlib.h>
#include <mmsystem.h>
#include <string>
#include <windows.h>
#pragma comment (lib, "winmm.lib")

using namespace std;

int main() {
    PlaySound(TEXT("Happy Birthday To You.wav"), NULL, SND_SYNC);
    system("pause");
    return 0;
}

C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|905|error: 'DWORD' does not name a type|

C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|906|error: 'UINT' does not name a type|

C:\Program Files (x86)\CodeBlocks\MinGW\include\mmsystem.h|907|error: typedef 'UINT' is initialized (use decltype instead)|

它只是在头文件中出现了很多这样的错误,我链接到 -lwinmm 并检查了库,它仍然弹出。

PS 我正在使用代码块。

您需要在 mmsystem.h 之前包含 windows.h windows.h 应该在您的包含中排在第一位。 mmsystem.h 使用 windows.h 中定义的类型(包括 DWORD 和 UINT)。