Click here to Skip to main content
13,092,310 members (60,157 online)
Rate this:
Please Sign up or sign in to vote.
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
BOOL CWavePlay::ReadWaveFile(CString szFilename)
	hmmio = mmioOpen((LPTSTR)&szFilename,NULL,MMIO_READ);
	ASSERT(hmmio);		//error here: hmmio=0x00000000
		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 28-Mar-12 19:17pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try this - hmmio = mmioOpen((LPTSTR)szFilename,NULL,MMIO_READ);
You could also use the PlaySound API with the SND_FILENAME flag.
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?
«_Superman_» 29-Mar-12 3:47am
The CString class has an overloaded LPCTSTR operator which returns a const TCHAR*.
So the inner cast is an explicit call to this overloaded operator which we then cast to a LPTSTR which is nothing but a TCHAR*.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

the solution is:
<pre>hmmio = mmioOpen((LPTSTR)(LPCTSTR)szFilename,NULL,MMIO_READ);

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 29 Mar 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100