0

I have simple windows app, generated from visual studio 2013 professional.

I want to play sound but it wont compile when i add the playsound function, The program works except the playsound function so i dont see any meaning to add the hole windows code.

In other examples the function is defined in mmsystem.h, but not in my environment - its declared in the playsoundapi.h. But i included both mmsystem.h and playsoundapi.h.

Code:

#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;

}

I get 2 error messages:

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
Niklas
  • 1,753
  • 4
  • 16
  • 35

0 Answers0