CString to string problem
Hi,
I m using a dll call to play a wav file .
It is like this Playfile("c:\temp\chimes.wav",2);
now i have used GetPathName property to get the path name of the selected file into the CString m_iResults.
Now if i use the syntax as Playfile(m_iResults,2); it gives me error saying - cannot convert parameter 1 from 'class CString' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
please provide me the solution or a way to solve this problem.
rutu.
Re: CString to string problem
Quote:
Originally posted by patil_ruturaj
Hi,
I m using a dll call to play a wav file .
It is like this Playfile("c:\temp\chimes.wav",2);
now i have used GetPathName property to get the path name of the selected file into the CString m_iResults.
Now if i use the syntax as Playfile(m_iResults,2); it gives me error saying - cannot convert parameter 1 from 'class CString' to 'char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
please provide me the solution or a way to solve this problem.
rutu.
You cannot "convert" a CString to a char*. A const char*, yes, but a char* - no. You can copy from a CString to a char buffer. You can also use GetBuffer/ReleaseBuffer, but I personally avoid these.
Quote:
See if Playfile(m_iResults.GetString(),2) works for you.
This will not work. GetString returns a const PCXSTR. Plus, the method is not available in MFC42 / MSVC 6.0.
Quote:
Playfile((LPCTSTR)m_iResults,2);
This will not work. The Playfile function requires a char*. Explicitly casting it to a const pointer will not cause it to behave any differently since CString has an operator LPCTSTR that allows for implicit casts.
Here's what I would do:
Code:
/* Contains filename to pass to Playfile, presumably obtained by calling CFileDialog::GetPathName */
CString m_iResults;
char szFileToPlay[MAX_PATH + 1] = {0};
strncpy( szFileToPlay, m_iResults, MAX_PATH );
Playfile( szFileToPlay, 2 );