.wav player problem

This is the code I have:
1
2
3
4
5
6
7
8
9
#include<iostream>
#include<conio.h>
#include<windows.h>

using namespace std;

int main (){
    PlaySound("C:\Documents and Settings\Jason\My Documents\Jason\My Music\5.LLT LOOKING LIKE THIS.mastered.wav", NULL, SND_ASYNC);
}

this was the result:
undefined reference to 'PlaySoundA@12'


Could someone please hep me to figure this out?
Last edited on
What library is PlaySound in? Are you linking against that library?

I was searching around and someone told me to use this program, I don't know how it works.
PlaySound is in
winmm.dll
Last edited on
My code now looks like this:
1
2
3
4
5
6
7
8
9
10
#include<iostream>
#include<conio.h>
#include <windows.h>
#include <mmsystem.h>
using namespace std;

int main (){
    PlaySound(TEXT("LOOKING LIKE THIS.wav"), NULL, SND_FILENAME);
}

I plays a sound but not the correct sound.
It plays the Windows error sound.
Last edited on
I think I fixed it...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#define WIN32_LEAN_AND_MEAN // prevent windows.h from including "kitchen sink"
#include <windows.h> // include using <>
#include <iostream>

int main()
{
    LPCSTR Application = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";

    // Command is passed as a non-const char* so should be passed in a modifiable buffer
    // Media file extension must be provided
    // Paths are quoted
    char Command[1024] = "\"C:\\Program Files\\Windows Media Player\\wmplayer.exe\""
        " \"C:\\Documents and Settings\\Jason\\My Documents\\Jason\\My Music\\LOOKING LIKE THIS.wav\"";

    // use -A form of struct as working with char, LPCSTR, etc rather
    // than TCHAR, LPCTSTR, etc
    STARTUPINFOA si = {0}; // zero struct
    si.cb = sizeof(si);

    PROCESS_INFORMATION pi = {0}; // zero struct

    // use -A form of function as working with char, LPCSTR, etc rather
    // than TCHAR, LPCTSTR, etc
    if( CreateProcessA(
                Application,
                Command,
                NULL,
                NULL,
                FALSE,
                NULL,
                0,
                NULL,
                &si,
                &pi) )
    {
        std::cout << "CreateProcess succeeded\n";

        WaitForSingleObject(pi.hProcess, INFINITE);

        DWORD exitCode = 0;
        GetExitCodeProcess(pi.hProcess, &exitCode);
        std::cout << "Exit code: " << exitCode << "\n";

        CloseHandle(pi.hThread);
        CloseHandle(pi.hProcess);
    }
    else
    {
        DWORD errCode = GetLastError();
        std::cerr << "CreateProcess failed\nError code: " << errCode << "\n";
    }

    return 0;
}
Topic archived. No new replies allowed.