Error C2664 Const Char Lpctstr
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you const char lpcwstr might have Meta Discuss the workings and policies of this site
Const Char Lpcstr
About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or
Const Char Lptstr
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
Cstring Const Char
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Cannot convert argument 1 from 'const char [5]' to 'LPCTSTR' up vote 2 down vote favorite I'm using this codeproject: http://www.codeproject.com/Articles/10138/Voice-Recording-Playing-back-using-simple-classes void CFisterDlg::OnRecord() { CString string; m_RecButton.GetWindowText(string); if(string == "Record") { StartRecordingToFile(); m_RecButton.SetWindowText("Stop"); } else { cannot convert parameter 1 from const char * to lpcwstr StopRecordingToFile(); m_RecButton.SetWindowText("Record"); } } But I get this error in numerous places: error C2664: 'void CWnd::SetWindowTextW(LPCTSTR)' : cannot convert argument 1 from 'const char [5]' to 'LPCTSTR' I think it has something to do with me using the latest version of visual studio (2013). c++ visual-studio-2013 wav share|improve this question asked Apr 22 '15 at 14:20 Taurian 2674822 @cybermonkey It's StackOverflow, not Grand Theft Auto: there's no steal. –black Apr 22 '15 at 14:27 @black There is, and it's widely frowned upon. See Meta. –cybermonkey Apr 22 '15 at 14:28 @cybermonkey See similar question. Has the same solution that i posted, yet i received 3 downvotes. Got to love stackoverflow. –Javia1492 Apr 22 '15 at 14:35 1 You have accepted a very damaging answer. Please consider changing it. –cybermonkey Apr 22 '15 at 20:01 @Yakk Look at Remy's third paragraph/code block. That will clarify the reason. –Javia1492 Apr 22 '15 at
here for a quick overview of the site Help Center Detailed answers to any questions you might convert char* to lpctstr have Meta Discuss the workings and policies of this site About char to lpctstr c++ Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads convert char* to lpcwstr 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 http://stackoverflow.com/questions/29800514/cannot-convert-argument-1-from-const-char-5-to-lpctstr programmers, just like you, helping each other. Join them; it only takes a minute: Sign up cannot convert from 'const char *' to 'LPCTSTR' in Debug up vote -1 down vote favorite When I compile my code in Debug-Mode I get error C2440 "cannot convert from 'const char *' to 'LPCTSTR'" When I compile the http://stackoverflow.com/questions/24605615/cannot-convert-from-const-char-to-lpctstr-in-debug code in Release-Mode it compiles without error, I don't even get a warning. the error occurs on line: LPCTSTR lpFileName = strFilenameIni.c_str(); I use LPCTSTR because I use GetPrivateProfileString to read values from an ini file, and i need to convert the file location to LPCTSTR so GetPrivateProfileString accepts it. I searched my compiler settings for something that can cause the deviation, but can't find anything. I just can't get it to compile in debug mode. I'm using Visual Studio 2005. Any help is appreciated. The code in question: std::string strFilenameIni = ""; //filename of ini file strFilenameIni = (char*)(void*)System::Runtime::InteropServices::Marshal::StringToHGlobalAnsi(textBox_ini_load->Text); //init ini-parser strings LPCTSTR lpFileName = strFilenameIni.c_str(); //<- this throws error in debug LPCTSTR lpSection = "CHECKSUM"; LPCTSTR lpKey = "CRC"; TCHAR TCHAR_inBuf[11]; //buffer for CRC-number GetPrivateProfileString(lpSection,lpKey,"",TCHAR_inBuf,11,lpFileName); //read CRC unsigned long ulCRC_IN = strtoul(TCHAR_inBuf,NULL,16); //convert to unsigned long c++ compiler-errors share|improve this question edited Jul 7 '14 at 8:03 Jerry YY Rain 1,50511027 asked Jul 7 '14 at 7:58 TBuc 62 1
Studio Languages , Windows Desktop Development > C++ Standards, Extensions, and Interop General discussion 5 Sign in to vote Note: This is https://social.msdn.microsoft.com/Forums/vstudio/en-US/c1b08c0a-a803-41c3-ac8c-84eba3be1ddb/faq-cannot-convert-from-const-char-to-lpctstr?forum=vclanguage a FAQ, not a question being asked. Question I'm trying to compile http://www.codeproject.com/Questions/396705/How-to-convert-string-to-LPCTSTR a piece of code such as: MessageBox("Hello world!"); ... when I compile the project, the compiler yields: error C2664: 'CWnd::MessageBoxW' : cannot convert parameter 1 from 'const char [12]' to 'LPCTSTR' What am I doing wrong? Problem This error message means that you are trying to pass a const char multi-byte string (const char [12]) to a function which expects a unicode string (LPCTSTR). The LPCTSTR type extends to const TCHAR*, where TCHAR is char when you compile for multi-byte and wchar_t for unicode. Since the compiler doesn't accept the char array, we can safely assume that the actual type of TCHAR, in this compilation, is wchar_t. Resolution You will * to lpcwstr have to do one of two things: Change your project configuration to use multibyte strings. Press ALT+F7 to open the properties, and navigate to Configuration Properties > General. Switch Character Set to "Use Multi-Byte Character Set". Indicate that the string literal, in this case "Hello world!" is of a specific encoding. This can be done through either prefixing it with L, such as L"Hello world!", or surrounding it with the generic _T("Hello world!") macro. The latter will expand to the L prefix if you are compiling for unicode (see #1), and nothing (indicating multi-byte) otherwise. Variations Another error message, indicating the same problem, would be: cannot convert parameter 1 from 'const char [12]' to 'LPCWSTR' Where LPCWSTR maps to a wchar_t pointer, regardless of your build configuration. This problem can be resolved primarily by using solution #2, but in some cases also #1. A lot of the Microsoft provided libraries, such as the Platform SDK, have got two variations of each function which takes strings as parameters. In case of a unicode build, the actual functions are postfixed W, such as the M
Tips/Tricks Top Articles Beginner Articles Technical Blogs Posting/Update Guidelines Article Help Forum Article Competition Submit an article or tip Post your Blog quick answersQ&A Ask a Question View Unanswered Questions View All Questions... C# questions Linux questions ASP.NET questions SQL questions VB.NET questions discussionsforums All Message Boards... Application Lifecycle> Running a Business Sales / Marketing Collaboration / Beta Testing Work Issues Design and Architecture ASP.NET JavaScript C / C++ / MFC> ATL / WTL / STL Managed C++/CLI C# Free Tools Objective-C and Swift Database Hardware & Devices> System Admin Hosting and Servers Java .NET Framework Android iOS Mobile SharePoint Silverlight / WPF Visual Basic Web Development Site Bugs / Suggestions Spam and Abuse Watch features Competitions News The Insider Newsletter The Daily Build Newsletter Newsletter archive Surveys Product Showcase Research Library CodeProject Stuff communitylounge Who's Who Most Valuable Professionals The Lounge The Insider News The Weird & The Wonderful The Soapbox Press Releases Non-English Language > General Indian Topics General Chinese Topics help What is 'CodeProject'? General FAQ Ask a Question Bugs and Suggestions Article Help Forum Site Map Advertise with us About our Advertising Employment Opportunities About Us Ask a Question All Questions All Unanswered FAQ How to convert string to LPCTSTR? Rate this: Please Sign up or sign in to vote. See more: C++ How to convert string to LPCTSTR? Posted 2-Jun-12 21:30pm Harmanjeet Singh1.4K Add a Solution 4 solutions Top Rated Most Recent Rate this: Please Sign up or sign in to vote. Solution 2 Accept Solution Reject Solution ATL provides some macros to do this. #include