PlaySound(MAKEINTRESOURCE, IDR_WAVE_RANDOM... problem
-
The need to compile wav files into a Doc/View plus modeless dialog MFC program led to abandoning a functioning mechanism to play random wav files:
PlaySound(“m_sStrConcatenatedStringWithPath”,NULL,SND_FILENAME|SND_SYNC);
(where sStrConcatenatedStringWithPath = “/path/201.wav” etc.) and adopting:
LPTSTR pRandomSound = m_sStrConcatenatedStringResource.GetBuffer(0);
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
m_sStrConcatenatedStringResource.ReleaseBuffer(0);
(where m_sStrConcatenatedStringResource = “IDR_WAVE_201” etc.). ...that fails to play the wav files even when...
PlaySound(MAKEINTRESOURCE, IDR_WAVE_201, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
will play the IDR_WAVE_201 resource. Many attempts experimenting different ways to cast the CString to the LPTSTR and obtaining the handle to the executable led to the code above, which still will not play the random sound resource. Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
The need to compile wav files into a Doc/View plus modeless dialog MFC program led to abandoning a functioning mechanism to play random wav files:
PlaySound(“m_sStrConcatenatedStringWithPath”,NULL,SND_FILENAME|SND_SYNC);
(where sStrConcatenatedStringWithPath = “/path/201.wav” etc.) and adopting:
LPTSTR pRandomSound = m_sStrConcatenatedStringResource.GetBuffer(0);
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
m_sStrConcatenatedStringResource.ReleaseBuffer(0);
(where m_sStrConcatenatedStringResource = “IDR_WAVE_201” etc.). ...that fails to play the wav files even when...
PlaySound(MAKEINTRESOURCE, IDR_WAVE_201, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
will play the IDR_WAVE_201 resource. Many attempts experimenting different ways to cast the CString to the LPTSTR and obtaining the handle to the executable led to the code above, which still will not play the random sound resource. Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
lctrncs wrote:
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
What
PlaySound()
are you using that takes four arguments?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
lctrncs wrote:
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
What
PlaySound()
are you using that takes four arguments?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
Thank you for responding. BOOL PlaySound( LPCSTR pszSound, HMODULE fdwSound, DWORD fdwSound) There are two arguments: LPCSTR (pszSound) and HMODULE (fdwSound) pRandomSound and GetModuleHandle(NULL) and two flags: DWORD fdwSound SND_SYNC|SND_RESOURCE Thanks again. I hope this answers your question.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
Thank you for responding. BOOL PlaySound( LPCSTR pszSound, HMODULE fdwSound, DWORD fdwSound) There are two arguments: LPCSTR (pszSound) and HMODULE (fdwSound) pRandomSound and GetModuleHandle(NULL) and two flags: DWORD fdwSound SND_SYNC|SND_RESOURCE Thanks again. I hope this answers your question.
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
lctrncs wrote:
BOOL PlaySound( LPCSTR pszSound, HMODULE fdwSound, DWORD fdwSound) There are two arguments: LPCSTR (pszSound) and HMODULE (fdwSound) pRandomSound and GetModuleHandle(NULL) and two flags: DWORD fdwSound SND_SYNC|SND_RESOURCE
You seem to be confused. Look at the code snippet in your original post. You are passing
PlaySound()
four arguments: 1)MAKEINTRESOURCE
, 2)pRandomSound
, 3)GetModuleHandle(NULL)
, and 4)SND_SYNC|SND_RESOURCE
. So my question still remains: where does this four-argument function come from? The answer to this may end up having no bearing on the actual problem, but if you can't post a working code snippet, it's kind of hard to come up with a useful answer."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
-
lctrncs wrote:
BOOL PlaySound( LPCSTR pszSound, HMODULE fdwSound, DWORD fdwSound) There are two arguments: LPCSTR (pszSound) and HMODULE (fdwSound) pRandomSound and GetModuleHandle(NULL) and two flags: DWORD fdwSound SND_SYNC|SND_RESOURCE
You seem to be confused. Look at the code snippet in your original post. You are passing
PlaySound()
four arguments: 1)MAKEINTRESOURCE
, 2)pRandomSound
, 3)GetModuleHandle(NULL)
, and 4)SND_SYNC|SND_RESOURCE
. So my question still remains: where does this four-argument function come from? The answer to this may end up having no bearing on the actual problem, but if you can't post a working code snippet, it's kind of hard to come up with a useful answer."Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
The BOOL PlaySound( LPCSTR pszSound, HMODULE fdwSound, DWORD fdwSound) comes from the "Multimedia: Platform SDK" section of the Visual C++ 6.0 MSDEV documentation. This specific use of the MAKEINTRESOURCE macro is documented in the "Technical Articles" section of the Visual C++ 6.0 MSDEV documentation in a file called "Moving Your Game to Windows, Part III. Does this answer you question?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
-
The need to compile wav files into a Doc/View plus modeless dialog MFC program led to abandoning a functioning mechanism to play random wav files:
PlaySound(“m_sStrConcatenatedStringWithPath”,NULL,SND_FILENAME|SND_SYNC);
(where sStrConcatenatedStringWithPath = “/path/201.wav” etc.) and adopting:
LPTSTR pRandomSound = m_sStrConcatenatedStringResource.GetBuffer(0);
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
m_sStrConcatenatedStringResource.ReleaseBuffer(0);
(where m_sStrConcatenatedStringResource = “IDR_WAVE_201” etc.). ...that fails to play the wav files even when...
PlaySound(MAKEINTRESOURCE, IDR_WAVE_201, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
will play the IDR_WAVE_201 resource. Many attempts experimenting different ways to cast the CString to the LPTSTR and obtaining the handle to the executable led to the code above, which still will not play the random sound resource. Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
When You add WAV resource by ID there is no way to call PlaySound (and other resource functions) by resource name and vice versa - when you add resource with resource name string - You can not access resource by it' ID. For this resource script file:
//Resources.h
#define SOUND_1//MyApp.rc
...
SOUND_1 WAV "snd1.wav"
"MOO" WAV "moo.wav"Valid PlaySound call is:
PlaySound(MAKEINTRESOURCE(SOUND_1), ...);
PlaySound("MOO", ...); -
The need to compile wav files into a Doc/View plus modeless dialog MFC program led to abandoning a functioning mechanism to play random wav files:
PlaySound(“m_sStrConcatenatedStringWithPath”,NULL,SND_FILENAME|SND_SYNC);
(where sStrConcatenatedStringWithPath = “/path/201.wav” etc.) and adopting:
LPTSTR pRandomSound = m_sStrConcatenatedStringResource.GetBuffer(0);
PlaySound(MAKEINTRESOURCE, pRandomSound, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
m_sStrConcatenatedStringResource.ReleaseBuffer(0);
(where m_sStrConcatenatedStringResource = “IDR_WAVE_201” etc.). ...that fails to play the wav files even when...
PlaySound(MAKEINTRESOURCE, IDR_WAVE_201, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE);
will play the IDR_WAVE_201 resource. Many attempts experimenting different ways to cast the CString to the LPTSTR and obtaining the handle to the executable led to the code above, which still will not play the random sound resource. Suggestions?
"For a successful technology, reality must take precedence over public relations, for nature cannot be fooled." Richard Feynman, Minority Report to the Official Report on the Space Shuttle Challenger Crash
Thanks to everyone at CodeProject! It appears that the original post may not be clear. Therefore, consider the following code snippet which includes much more information about the problem and the (failed) attemtps to resolve it. Again, for reasons this beginner has yet to understand, PlaySound works fine with a filename constructed from a CString and a random number (/path/filename1.wav), but fails when concatenated CStrings are used to create a resouce identifier (IDR_WAVE_1). Please consider the code and coments below.
//Create random resource ID (similar approach used to create random wave file names)
int m\_nRandomSound; m\_nRandomSound = getrandom( 500, 509 ); //Place the random number into the variable n\_nRandomRecord CString m\_sStrRandomSound; m\_sStrRandomSound = ""; CString m\_sStrRandomResourcePrefix; //Create the resource prefix m\_sStrRandomResourcePrefix = "IDR\_WAVE\_"; m\_sStrRandomSound.Format("%d", m\_nRandomSound); //Convert the random integer to a CString
//Concatentate the strings into the resource identifier
CString m_sStrRandomResourcePrefixWav;
m_sStrRandomResourcePrefixWav = m_sStrRandomResourcePrefix + m_sStrRandomSound;//Set the resource identifier directly
CString m_sStrRandomResourcePrefixWav2;
m_sStrRandomResourcePrefixWav2="IDR_WAVE_503";//
//
//Demonstrate function similar method that plays sounds using concatenated CString of path/filename
PlaySound(m_sStrRandomSoundPathWav, GetModuleHandle(NULL), SND_FILENAME|SND_SYNC );
//PLAYS from concatenated CString
//(e.g. \path\filename?.wav - where ? is an integer converted to a CString)PlaySound(MAKEINTRESOURCE(IDR_WAVE_503), GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE );
//PLAYS IDR_WAVE_503
//which is directly entered an not subtituted in any way
//
//
//ATTEMPTS TO EMPLOY CONCATENATED STRING TO PLAY RANDOM WAVE FILE//PlaySound(MAKEINTRESOURCE(m_sStrRandomResourcePrefixWav), GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE );
//error C2440: 'type cast' : cannot convert from 'class CString' to 'unsigned short'
//included for completeness//PlaySound(IDR_WAVE_503, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE );
//error C2664: 'PlaySoundA' : cannot convert parameter 1 from 'const int' to 'const char *'
//included for completenessPlaySound(m_sStrRandomResourcePrefixWav2, GetModuleHandle(NULL), SND_SYNC|SND_RESOURCE );
//Compiles b