Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to make an audio player that plays .wav files. I wrote a function ReadWaveFile(CString szFilename) for reading the wave data of the file into the WAVEHDR structure. In this function
<pre>
BOOL CWavePlay::ReadWaveFile(CString szFilename)
{
	hmmio = mmioOpen((LPTSTR)&szFilename,NULL,MMIO_READ);
	ASSERT(hmmio);		//error here: hmmio=0x00000000
	if(hmmio==0)
		return FALSE;
        ....
}

mmioOpen is always returning 0 whenever I pass a filepath to this function for opening the specified file. And what baffles me is when i pass the filepath explicitly in mmioOpen API the code works; i.e., a valid handle is returned.
can some body explain why is this happening??
Posted

Try this - hmmio = mmioOpen((LPTSTR)szFilename,NULL,MMIO_READ);
You could also use the PlaySound API with the SND_FILENAME flag.
 
Share this answer
 
Comments
stib_markc 29-Mar-12 1:50am    
That is what i actually did, please see my code...
PlaySound works only with small files. As I said I am trying to make an audio player, not trying to add (small)sounds to my program.
«_Superman_» 29-Mar-12 2:07am    
If you look carefully you will see that an & is missing in my post.
Are you sure PlaySound only works with small files. I'm not aware of this limitation. Please check with multiple files.
stib_markc 29-Mar-12 2:58am    
error C2440: 'type cast' : cannot convert from 'class CString' to 'char *' the code doent build... and yes the PlaySound function doesn't play the file fully(if it is larger than normal windows sound files). I checked it with multiple files.
«_Superman_» 29-Mar-12 3:30am    
Try this - hmmio = mmioOpen((LPTSTR)(LPCTSTR)szFilename,NULL,MMIO_READ);
stib_markc 29-Mar-12 3:39am    
Thank you <<_Superman_>> the problem is solved.... but why this type of casting is needed, I mean what is difference?
the solution is:
<pre>hmmio = mmioOpen((LPTSTR)(LPCTSTR)szFilename,NULL,MMIO_READ);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900