|
-
March 22nd, 2009, 07:34 PM
#1
sndPlaySound Wont play
Hi
Im back =)
Well I was trying to play a .wav file from my app path with
PlaySound("BELLS.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
and tryed
sndPlaySound ("BELLS.wav",SND_LOOP|SND_ASYNC);
the PlaySound wont do nothing but the sndPlaySound will make beeps like the is not in the apppath witch it was
So.... I gave up and moved on an tryed playing it from the resources.
I added the resources an the BEELS.wav to the resources
An used this code to try to play it
sndPlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );
and tryed
PlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );
and tryed
HANDLE sndBoing;
HRSRC hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_WAVE1), "WAVE");
hResInfo = FindResource(hInstance, MAKEINTRESOURCE(IDR_WAVE1), "WAVE");
sndBoing = LoadResource(hInstance, hResInfo);
const char* sndRes = (const char*)LockResource(sndBoing);
PlaySound(sndRes, SND_MEMORY|SND_ASYNC|SND_NODEFAULT);
UnlockResource(sndRes);
But none of the worked
Here is a screen shot of my scr
http://img19.picoodle.com/img/img19/...em_040fb11.jpg
-
March 23rd, 2009, 04:41 AM
#2
Re: sndPlaySound Wont play
 Originally Posted by rentagoth
I was trying to play a .wav file from my app path with
PlaySound("BELLS.wav",NULL,SND_FILENAME|SND_LOOP|SND_ASYNC);
Well, it is obvious that the "current working directory" might be not the same as the one containing "BELLS.wav" file.
You have to pass in the full pathe name to the PlaySound call.
 Originally Posted by rentagoth
An used this code to try to play it
sndPlaySound(MAKEINTRESOURCE(IDR_WAVE1), SND_RESOURCE |SND_ASYNC );
1. Of course, it is wrong. And it cannot just compile!
You forgot the second parameter that must be the handle to the executable file that contains the resource to be loaded.
The correct call should look like:
Code:
PlaySound(MAKEINTRESOURCE(IDR_WAVE1), AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
2. Is the IDR_WAVE1 correct ID? Or it looks like the text "IDR_WAVE1"?
In latter case you must not use MAKEINTRESOURCE macro - just:
Code:
PlaySound("IDR_WAVE1", AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
Victor Nijegorodov
-
March 23rd, 2009, 01:16 PM
#3
Re: sndPlaySound Wont play
 Originally Posted by VictorN
Well, it is obvious that the "current working directory" might be not the same as the one containing "BELLS.wav" file.
You have to pass in the full pathe name to the PlaySound call.
1. Of course, it is wrong. And it cannot just compile!
You forgot the second parameter that must be the handle to the executable file that contains the resource to be loaded.
The correct call should look like:
Code:
PlaySound(MAKEINTRESOURCE(IDR_WAVE1), AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
2. Is the IDR_WAVE1 correct ID? Or it looks like the text "IDR_WAVE1"?
In latter case you must not use MAKEINTRESOURCE macro - just:
Code:
PlaySound("IDR_WAVE1", AfxGetResourceHandle(), SND_RESOURCE | SND_ASYNC );
I tryed that and none of them worked.
Maybe is me trying to play the sound in my .dll
Ok playsound will not work in my .dll for nothing
PlaySound("C:\\BELLS.wav", NULL, SND_FILENAME);
but this works
sndPlaySound ("C:\\BELLS.wav",SND_LOOP|SND_ASYNC)
how do I use sndPlaySound to play a sound from my resources
Here is was my resource script file looks like
////////////////////////////HL2.rs///////////////////////
// Microsoft Visual C++ generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// WAVE
//
IDR_WAVE1 WAVE "BELLS.wav"
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
here is what my resource.h looks like
/////////////////////resource.h///////////////////////
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by HL2.rc
//
#define IDR_WAVE1 102
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 103
#define _APS_NEXT_COMMAND_VALUE 40002
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
here is what my code looks like
Im trying to do all this in a .dll not an .exe
http://img19.picoodle.com/img/img19/...em_040fb11.jpg
Srry for the slopy post I dont see a code block option on the post
[code/] [code]
Last edited by rentagoth; March 23rd, 2009 at 01:33 PM.
-
March 23rd, 2009, 04:20 PM
#4
Re: sndPlaySound Wont play
 Originally Posted by rentagoth
...
Im trying to do all this in a .dll not an .exe
What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
How are you using this dll?
Victor Nijegorodov
-
March 23rd, 2009, 09:52 PM
#5
Re: sndPlaySound Wont play
 Originally Posted by VictorN
What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
How are you using this dll?
My Use of MFC is set to Use Standard Windows Libraries
-
March 24th, 2009, 05:31 AM
#6
Re: sndPlaySound Wont play
And what about:
PlaySound(_T(".Default"),NULL, SND_APPLICATION|SND_NODEFAULT);
this will play default bell sound in windows.
-
March 24th, 2009, 05:36 AM
#7
Re: sndPlaySound Wont play
 Originally Posted by rentagoth
My Use of MFC is set to Use Standard Windows Libraries
Sorry, but I couldn't understand what you meant.
Victor Nijegorodov
-
March 24th, 2009, 05:39 AM
#8
Re: sndPlaySound Wont play
 Originally Posted by rentagoth
... Im trying to do all this in a .dll not an .exe
And would the same code work if you placed it in the exe?
Victor Nijegorodov
-
March 24th, 2009, 11:08 AM
#9
Re: sndPlaySound Wont play
 Originally Posted by VictorN
And would the same code work if you placed it in the exe?
this is that code that worked in the .exe
PlaySound("BELLS.WAV", NULL, SND_ASYNC);
It play the bells.wave from where the .exe is
-
March 24th, 2009, 11:27 AM
#10
Re: sndPlaySound Wont play
 Originally Posted by rentagoth
this is that code that worked in the .exe
PlaySound("BELLS.WAV", NULL, SND_ASYNC);
It play the bells.wave from where the .exe is
Well, if this code does work being in exe and does NOT work being in dll then 99.9% that the problem is in your dll.
Therefore I already asked you but haven't got an answer:
 Originally Posted by VictorN
What type of dll? Is it an MFC dll or not? If MFC - is it a regular or estension dll?
How are you using this dll?
Note, that if it is an MFC regular dll then you have to add
Code:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
to the beginning of the exported functions. See MSDN for details
Victor Nijegorodov
-
March 27th, 2009, 01:15 AM
#11
Re: sndPlaySound Wont play
Nvm I just gave up on it
Thank you for your help =)
much appreciated
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|