Error C2664 Play Sound
Contents |
2 → New Topic/Question Reply 16 Replies - 5667 Views - Last Post: 21 May 2010 - 09:57 AM Rate Topic: #1 liverpool0912 New
Error C2664 Cannot Convert Parameter
D.I.C Head Reputation: 0 Posts: 42 Joined: 04-June 08 Play sound error c2664 cannot convert parameter 1 from Posted 26 August 2008 - 05:28 AM #include
Error C2664 In C++
sleep function void main(void) { char filename[255]="26 - Halo.wav"; //file must be in same directory as executeable sndPlaySound(filename,SND_LOOP); //using SND_ASYNC will cause program execution to continue //using SND_SYNC will cause error c2664 lpcwstr the program to halt execution until //the sound is done playing //using SND_LOOP will cause the sound to play over and over. //SND_LOOP must be used with SND_SYNC like so, //sndPlaySound(filename, SND_SYNC | SND_LOOP);; } c:\users\liverpool0912\documents\visual studio 2005\projects\fh\fh\fhd.cpp(14) : error C2664: 'sndPlaySoundW' : cannot convert parameter 1 from 'char [255]' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, error c2664 cannot convert argument C-style cast or function-style cast whats the problem and another question can i use .mp3 files instead of wav files? Is This A Good Question/Topic? 0 Back to top MultiQuote Quote + Reply Replies To: Play sound #2 gabehabe GabehabeSwamp Reputation: 1429 Posts: 11,005 Joined: 06-February 08 Re: Play sound Posted 26 August 2008 - 06:00 AM The sndPlaySound function looks for a type LPCWSTR instead of char[] Try this: LPCWSTR lpFileName = "26 - Halo.wav" Hope this helps Was This Post Helpful? 0 Back to top MultiQuote Quote + Reply #3 liverpool0912 New D.I.C Head Reputation: 0 Posts: 42 Joined: 04-June 08 Re: Play sound Posted 26 August 2008 - 06:26 AM #include
function in Visual Studio 2005, and find myself coming up short in getting it to work. I have recieved many
Error C2664 Cannot Convert Parameter From Const Char To Lpcwstr
compile errors, and never successfully have gotten it to function. I mfc error c2664 am using VC++ console application, WITHOUT a precompiled header. My main form is too long to list, but here is the code that is runable. #include
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about http://stackoverflow.com/questions/28946721/cannot-convert-parameter-1-from-const-wchar-t-to-lpctstr-in-mfc-c-proj Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cannot convert parameter 1 from 'const wchar_t *' to 'LPCTSTR' in MFC / C++ error c2664 project up vote 3 down vote favorite I get a compilation error on the line: MessageBox(e.getAllExceptionStr().c_str(), _T("Error initializing the sound player")); Error 4 error C2664: 'CWnd::MessageBoxA' : cannot convert parameter 1 from 'const wchar_t *' to 'LPCTSTR' c:\users\daniel\documents\visual studio 2012\projects\mytest1\mytest1\main1.cpp 141 1 MyTest1 I don't know how to resolve this error, I tried the following: MessageBox((wchar_t *)(e.getAllExceptionStr().c_str()), _T("Error initializing the sound player")); MessageBox(_T(e.getAllExceptionStr().c_str()), _T("Error initializing the sound player")); I am error c2664 cannot using the setting "Use Multi-Byte Character Set" and I don't want to change it. c++ string mfc tchar lpcwstr share|improve this question edited Mar 9 '15 at 16:21 Mr.C64 18.9k64180 asked Mar 9 '15 at 16:13 tyebillion 505315 I'm not sure why getAllExceptionStr returns a wide string if you're stuck with ANSI, but then you'll have to convert (note: not cast) it. –chris Mar 9 '15 at 16:17 add a comment| 4 Answers 4 active oldest votes up vote 4 down vote accepted The easiest way is simply to use MessageBoxW instead of MessageBox. MessageBoxW(e.getAllExceptionStr().c_str(), L"Error initializing the sound player"); The second easiest way is to create a new CString from the original; it will automatically convert to/from wide string and MBCS string as necessary. CString msg = e.getAllExceptionStr().c_str(); MessageBox(msg, _T("Error initializing the sound player")); share|improve this answer answered Mar 9 '15 at 16:18 Mark Ransom 180k22194398 I think if the purpose of the conversion is to just pass the string as a temporary to some function/method like MessageBox() in the above case, using CW2T for the conversion is more efficient than creating a new CString instance. CString has more features than CW2T, but also more overhead. Moreover, CW2T and the other ATL conve