Search code examples
cwindowsplaysound

C Playsound Function returns -1073741819 exit code and doesn't play mp3 file


Some parts that includes important function of Playsound

MCI_OPEN_PARMS m_mciOpenParms;
MCI_PLAY_PARMS m_mciPlayParms;
DWORD m_dwDeviceID;
MCI_OPEN_PARMS mciOpen;
MCI_PLAY_PARMS mciPlay;

int dwID;
//
#define TITLE_SPACE 55
#define TITLE_ENTER 10
/*music address*/#definedecision_change "C:\\Users\\chanho\\Desktop\\decision_change.wav"
#define main_theme "C:\\Users\\chanho\\Desktop\\FlappyChicken.mp3"

part of my code

        if (inner_time == 0)
    {
        //bgm
        mciOpen.lpstrElementName = TEXT(main_theme);
        mciOpen.lpstrDeviceType = "mpegvideo";
        mciSendCommand(NULL, MCI_OPEN, MCI_OPEN_ELEMENT | MCI_OPEN_TYPE, (DWORD)(LPVOID)&mciOpen);
        dwID = mciOpen.wDeviceID;
        mciSendCommand(dwID, MCI_PLAY, MCI_DGV_PLAY_REPEAT, (DWORD)(LPVOID)&m_mciPlayParms);
        //
    }

It worked well on other PCs or laptop, but when I insert this code and comfile it, It returns weird exit code and stops at the moment of "part of my code"

when I delete this "part of my code", it worked without problem.

No error occured on comfiling this code, even though it has weird exit code.

Could anyone explain me why only my laptop returns that -107~~~ code thing and how to fix it?


Solution

  • well -1073741819 is 0xc0000005 in hex, which is ACCESS_VIOLATION

    maybe you dont have read permission on the file

    see Exception Error c0000005 in VC++

    On second thoughts this is not a perm thing but a memory read write error. I suspect that you are not testing a return value somewhere and are thus using a NULL pointer that was returned by a function. You dont show enough code to be able to tell though