PlaySound不会编译

时间:2016-10-03 12:18:43

标签: c++ windows playsound

我有一个简单的Windows应用程序,由visual studio 2013专业人员生成。

我想播放声音但是当我添加playound函数时它不会编译, 该程序的工作除了playound函数,所以我没有看到添加孔窗口代码的任何意义。

在其他示例中,函数在mmsystem.h中定义,但不在我的环境中定义 - 它在playsoundapi.h中声明。 但我包括mmsystem.h和playsoundapi.h。

代码:

#include "stdafx.h"
#include "cppWindowsApp.h"
#include<playsoundapi.h>
#include<mmsystem.h>

#define MAX_LOADSTRING 100  

using namespace std;

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (message)
    {
    case WM_CREATE:
         PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS); // < ---- here
    break;
case WM_COMMAND:
    wmId    = LOWORD(wParam);
    wmEvent = HIWORD(wParam);
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_ABOUT:
        DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
        break;
    case IDM_EXIT:
        DestroyWindow(hWnd);
        break;
    default:
        return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;
case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    // TODO: Add any drawing code here...
    EndPaint(hWnd, &ps);
    break;
case WM_DESTROY:
    PostQuitMessage(0);
    break;
default:
    return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;

}

我收到2条错误消息:

Error Link1120: Unresolved externals

Error LNK2019: unresolved external symbol __imp__PlaySoundW@12  
referenced in function "long __stdcall WndProc(struct HWND__ *,unsigned 
int,unsigned int,long)" (?WndProc@@YGJPAUHWND__@@IIJ@Z) D:\VS\Project\[bok]\ 
[progamming windows]\cppWindowsApp\cppWindowsApp\cppWindowsApp.obj  
cppWindowsApp

0 个答案:

没有答案