Warum funktioniert PlaySound() hier nicht?!
-
Hallo,
ich habe ein Problem
Also meine *.cpp-Datei:#include <windows.h> #include "mmsystem.h" HINSTANCE hInst; LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); int WINAPI WinMain (HINSTANCE hI, HINSTANCE hPrI, PSTR szCmdLine, int iCmdShow) { char szName[] = "Fensterklasse"; HBRUSH MyBrush = CreateSolidBrush(RGB(255,255,51)); WNDCLASS wc; wc.style = CS_HREDRAW | CS_VREDRAW; // CS = "class style" wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hI; wc.hIcon = LoadIcon (NULL, IDI_WINLOGO); wc.hCursor = LoadCursor (NULL, IDC_ARROW); wc.hbrBackground = MyBrush; wc.lpszMenuName = NULL; wc.lpszClassName = szName; RegisterClass (&wc); HWND hwnd = CreateWindow (szName, "Soundtest", WS_SYSMENU | WS_THICKFRAME, 300, 230, 500, 200, NULL, NULL, hI, NULL); ShowWindow (hwnd, iCmdShow); UpdateWindow (hwnd); // Nachrichten-Schleife MSG msg; while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); DispatchMessage (&msg); } return msg.wParam; } // Windows-Nachrichten-Prozedur LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRUCT ps; HWND hwndButton1; switch (message) { case WM_PAINT: hdc = BeginPaint (hwnd, &ps); TextOut (hdc, 20, 20, "Soundtest", 20); EndPaint (hwnd, &ps); return 0; case WM_CREATE: hwndButton1 = CreateWindow ( "button", "Abspielen", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 150, 20, 100, 40, hwnd, (HMENU)1, (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL); return 0; case WM_COMMAND: if(LOWORD(wParam) == 1) { PlaySound("sound1", hInst, SND_RESOURCE); } return 0; case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, message, wParam, lParam); }und meine *.rc-Datei:
#include <windows.h> sound1 WAVE "C:\\Windows\\Media\\tada.wav"Das ganze gibt immer so eine blöde Meldung:
burnin joint.obj : error LNK2001: Nichtaufgeloestes externes Symbol __imp__PlaySoundA@12
Release/burnin joint.exe : fatal error LNK1120: 1 unaufgeloeste externe Verweise
Fehler beim Ausführen von link.exe.Kann mir jemand sagen woran dass liegt?
Bin schon ca. 1 Monat dabei und kriege es nicht gebacken
Grüße,
Björn
-
Du musst noch die Library Winmm.lib dazu linken.
Denn mit der Headerdatei "mmsystem.h" hast du nur die Funktionsköpfe, also die Beschreibung, wie man die Fnkt. aufrufen muss.
Die Lib brauchst du, damit das Programm auch genau weiß, wass denn nun genau PlaySound macht.Das Hinzufügen machst du in den Projekteinstellungen unter Linker/Zusätzliche Abhängigkeiten.
-
UFF - diese Kleinigkeiten immer....
Geht jetzt - danke!
Björn