I'm trying to make a specific .wav file play that I have added as a resource in my project. And when I run the program no sound is played.
I've tried doing:
PlaySound(TEXT("SystemStart"), NULL, SND_ALIAS);
Which works and plays correctly.
Then I tried to define the location of the wav file on my computer with:
PlaySound(TEXT("D:/TestSounds/sound1.wav"), NULL, SND_ASYNC);
Which also works correctly!
But the problem starts when I try to run the file from a resource
I've tried doing:
PlaySound(MAKEINTRESOURCE(IDR_WAVE1), GetModuleHandle(NULL), SND_RESOURCE);
And also tried using
BOOL PlayResource(LPCWSTR lpName)
{
BOOL bRtn;
HANDLE hRes;
// Find the WAVE resource.
HRSRC hResInfo = FindResource(NULL, lpName, TEXT("WAVE"));
if (hResInfo == NULL)
return FALSE;
// Load the WAVE resource.
hRes = LoadResource(NULL, hResInfo);
if (hRes == NULL)
return FALSE;
// Lock the WAVE resource and play it.
const char* lpRes = (const char*)LockResource(hRes);
if (lpRes != NULL) {
bRtn = PlaySound((LPCUWSTR)lpRes, NULL, SND_MEMORY | SND_ASYNC);
UnlockResource(hRes);
}
else
bRtn = 0;
// Free the WAVE resource and return success or failure.
FreeResource(hRes);
return bRtn;
}
Any help is appreciated