Waitrud Weber’s blog

things and reminders for memories

Visual Studio Sounds program: They sound at the same time.

Inclusion of mmsystem and load of wave files for sounds different wav files at the same time were success on the code below.
However, we can not find the sounds file.

 

#include 
#include 
#pragma comment(lib,"winmm.lib")
#define MSG(m) {\
    MessageBoxA(NULL,m,NULL,MB_OK);}

HWND hwnd;
HINSTANCE hinst;
static MCI_OPEN_PARMS open, open2, open3;
static MCI_PLAY_PARMS play, play2, play3;

int mm_initialization();
int mm_initialization() {
    int result;
    LPSTR buf;
    char temp[512];
    int i;

    buf = (LPSTR)temp;

//    open.lpstrDeviceType = (LPCWSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
//    open.lpstrElementName = (LPCWSTR)"thunder.wav";
//    open.lpstrDeviceType = (LPCWSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
//    open.lpstrElementName = (LPCWSTR)"rain2.wav";
    open.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
    open.lpstrElementName = (LPCSTR)"thunder.wav";
    open.lpstrDeviceType = (LPCSTR)MCI_DEVTYPE_WAVEFORM_AUDIO;
    open.lpstrElementName = (LPCSTR)"rain2.wav";

    for (i = 0; i < 10; i++) {
        result = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT,
            (DWORD_PTR)&open);
        result = mciSendCommandA(0, MCI_OPEN, MCI_OPEN_TYPE | MCI_OPEN_TYPE_ID | MCI_OPEN_ELEMENT,
            (DWORD_PTR)&open3);

        if (result) {
            mciGetErrorStringA(result, buf, sizeof(buf));
            MSG(buf);
            if (i >= 9) {
                PostQuitMessage(0);
                return -1;
            }
            Sleep(1000);
        }
    }

    play.dwCallback = (DWORD)hwnd;
    play3.dwCallback = (DWORD)hwnd;

	return 1;
}
...

    case WM_CREATE:
//        a = mm_initialization();
        break;
...

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
   a = mm_initialization();
...

---

Reference:

[1] about mmsystem.h : https://bituse.info/winapi/35

[2] including windows.h before mmsystem.h : https://docs.microsoft.com/en-us/previous-versions//dd757160(v=vs.85)