Error C2664 Atl Cstringt
error: error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'Solution1:In Project Menu select your Project Properties.In Configuration PropertiesSet "Character Set" as "Use Multi-Byte Character Set"Solution2:where ever you are declaring "CString" variable add Unicode support.Example:CString csStr(_T("")); //_T("") is for unicode support Posted by VS at 5:18 AM Labels: CString ERROR No comments: Post a Comment Newer Post Older Post Home Subscribe to: Post Comments (Atom) Labels API Application Bugs C# CDHtmlDialog CIPAddressCtrl Code to Avoid Multiple Instance COM Crash Cstring CString Conversion CString ERROR CstringArray Date/Time Debugging Tips DLL DoEvents VB6.0 File FileDialog Folder Delete Folder Select Dialog GUID Hide the Taskbar application button Icon IGlobalInterfaceTable INI Files Internet Internet explorer Interprocess communication Library File Linker Errors Marshalling MFC Ms Dos Pipe Recycle Bin Registry SDI Shell Operation Shortcut SQLITE STL Task Manager Template Thread Troubleshooting UI Tricks UnManaged and Managed (CLR) Data Type UnMashalling Using DLLs and The Windows API in Visual Basic 6.0 WebBrowser control Windows Windows Vista User Account Control WinInet xtreme toolkit Hit Counter Blog Archive ► 2012 (1) ► May (1) ► May 24 (1) ► 2010 (4) ► June (1) ► Jun 16 (1) ► April (1) ► Apr 01 (1) ► March (1) ► Mar 21 (1) ► January (1) ► Jan 21 (1) ▼ 2009 (52) ► December (2) ► Dec 15 (1) ► Dec 02 (1) ► November (6) ► Nov 29 (1) ► Nov 17 (2) ► Nov 13 (2) ► Nov 10 (1) ► October (1) ► Oct 31 (1) ► September (6) ► Sep 23 (1) ► Sep 22 (1) ► Sep 21 (1) ► Sep 17 (2) ► Sep 07 (1) ► August (3) ► Aug 21 (1) ► Aug 11 (2) ► July (3) ► Jul 20 (1) ► Jul 16 (2) ► May (9) ► May 30 (1) ► May 25 (2) ► May 22 (2) ► May 15 (3) ► May 14 (1) ► April (5) ► Apr 16 (5) ► March (2) ► Mar 26 (1) ► Mar 13 (1) ► February (6) ► Feb 28 (1) ► Feb 27 (1) ► Feb 21 (2) ► Feb 07 (2) ▼ January (9) ► Jan 27 (1) ► Jan 23 (1) ► Jan 17 (1) ► Jan 16 (1) ▼ Jan 01 (5) How to include library F
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 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 http://vcprogrammingtips.blogspot.com/2009/01/error-c2664-void-atlcstringt.html programmers, just like you, helping each other. Join them; it only takes a minute: Sign up cannot convert argument 1 from 'ATL::CStringT>>' to 'const char *' up vote 0 down vote favorite How to convert this way properly? VARIANT varIndex; CString csIndex; //Index BSTR csIndex = (LPCSTR)(_bstr_t)vtIndex; csIndex.MakeUpper(); if (csIndex.Left(3) == PROCESSUS_TABLE) { lIndex = atoi((LPCSTR)csIndex.Mid(3)); http://stackoverflow.com/questions/22916601/cannot-convert-argument-1-from-atlcstringtwchar-t-atlstrtraitatlwchar-t-a if ((unsigned long)lIndex<0) return E_INVALIDARG; } Error message: C2664: 'int atoi(const char *)' : cannot convert argument 1 from 'ATL::CStringT>>' to 'const char *' I couldn't find how to fix this, any good idea, please? c++ mfc atl cstring share|improve this question asked Apr 7 '14 at 15:21 user3477233 175 Possibly related: stackoverflow.com/a/10578592/1938163 –Marco A. Apr 7 '14 at 15:26 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted The variable 'csIndex' is a unicoce string(wchar_t), while the macro LPCSTR is for the ansi string (char). So you should use Unicode functions, the code will be: lIndex = _wtoi((LPCWSTR)csIndex.Mid(3)); There's no problem with this line: csIndex = (LPCSTR)(_bstr_t)vtIndex; It is because that the smart pointer type _bstr_t can handle char*/wchar_t* conversion automatically. share|improve this answer answered Apr 7 '14 at 15:28 Matt 4,7311127 add a comment| up vote 1 down vote CComVariant::ChangeType makes it available to you through .bstrVal member, _ttoi instead of atoi: VARIANT vtInd
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 Stack Overflow the company Business Learn http://stackoverflow.com/questions/18155195/cannot-convert-parameter-1-from-const-char-6-to-const-wchar-t more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags https://bytes.com/topic/c/answers/673968-problem-cstrings-format 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 char [6]' to 'const wchar_t * up vote 0 down vote favorite I'm new to MFC and I don't error c2664 know what to do with this error. ERROR error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [6]' to 'const wchar_t *' heres the line: m_Echo1.Format("%d %",state.dwMemoryLoad); mfc cstring share|improve this question asked Aug 9 '13 at 20:34 user2668338 313 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted By default a Windows app is set to use 16-bit characters, not 8-bit characters. Change your error c2664 atl quoted string to L"%d %" to specify a string of 16-bit characters. share|improve this answer answered Aug 9 '13 at 23:42 ScottMcP-MVP 8,9592613 1 Two comments: It's almost always better to use the T macros - so _T("%d %%"). And a single, standalone % is not a valid format specifier. I believe that newer versions of the Microsoft libraries raise a security exception at runtime when they encounter one. –Nik Bougalis Aug 10 '13 at 15:26 add a comment| up vote 1 down vote There are 2 distinct errors with the line of code you posted: The format string contains an illegal format specifier (trailing %). If you want a format string to contain a literal percent-sign it has to be escaped using %%. You are using a string literal that does not match the required encoding, i.e. a mismatch between ANSI and UNICODE character encoding. If m_Echo1 is of type CString the parameter has to be wrapped inside a _T or TEXT macro: _T( "%d %%" ). If m_Echo1 is of type CStringW the parameter must be passed as a UNICODE string literal by prepending it with L: L"%d %%". Note: The error message you posted does not match the line of code. The error message refers to const char [6] while the string literal in your code is of type const char
and get tips & solutions from a community of 418,505 IT Pros & Developers. It's quick & easy. Problem with CString's Format P: 3 ProgMaster I've used the Cstring format to convernt a CTime into a a CString, yet I get an error message, here's the code: void CTimerDlg::OnTimer(UINT_PTR nIDEvent) { CString m_sTime; // TODO: Add your message handler code here and/or call default CTime CurTime = CTime::GetCurrentTime(); m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond()); UpdateData(FALSE); CDialog::OnTimer(nIDEvent); } The Error message is : error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [9]' to 'const wchar_t *' How do I do this? Jul 7 '07 #1 Post Reply Share this Question 5 Replies Expert Mod 100+ P: 931 Meetee I've used the Cstring format to convernt a CTime into a a CString, yet I get an error message, here's the code: void CTimerDlg::OnTimer(UINT_PTR nIDEvent) { CString m_sTime; // TODO: Add your message handler code here and/or call default CTime CurTime = CTime::GetCurrentTime(); m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond()); UpdateData(FALSE); CDialog::OnTimer(nIDEvent); } The Error message is : error C2664: 'void ATL::CStringT::Format(const wchar_t *,...)' : cannot convert parameter 1 from 'const char [9]' to 'const wchar_t *' How do I do this? I think const wchar_t * typed parameter should be passed to CurTime.GetHour() function and you have passes const char [9] types parameter. Which causes such an error Jul 7 '07 #2 reply Expert Mod 5K+ P: 8,904 weaknessforcats m_sTime.Format ("%d,%d,%d", CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond()); If you are using this should be: [code=c] m_sTime.Format (TEXT("%d,%d,%d"), CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond()); Jul 7 '07 #3 reply P: 3 ProgMaster If you are using this should be: [code=c] m_sTime.Format (TEXT("%d,%d,%d"), CurTime.GetHour(), CurTime.GetMinute(),CurTime.GetSecond()); Thank you very much, the code now works perfectly, but could you please tell me what caused the error, becuase I took the code directly from a tutorial about Visual C++. And what does the command "TEXT(..)" do? Jul 8 '07 #4 reply Expert Mod 5K+ P: 8,904 weaknessforcats Thank you very much, the code now works perfectly, but could you please tell me what caused the error, becuase I took the code directly from a tutorial abou