我有简单的 Windows 应用程序,由 Visual Studio 2013 Professional 生成。
我想播放声音,但是当我添加 playsound 函数时它不会编译,该程序除了 playsound 函数之外都可以工作,所以我看不到添加孔 windows 代码的任何意义。
在其他示例中,该函数在 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