Error C2664 Cannot Convert Parameter From Const Char To Lpcwstr
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss
Error C2664 Cannot Convert Parameter 1 From 'const Char *' To 'char *'
the workings and policies of this site About Us Learn more cannot convert from const char to lpctstr about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack
Cannot Convert From 'const Char [14]' To 'lpcwstr'
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 const wchar_t *' to 'lpcstr' each other. Join them; it only takes a minute: Sign up cannot convert parameter 1 from 'char' to 'LPCWSTR' up vote 21 down vote favorite 10 I keep getting this error: cannot convert parameter 1 from 'char' to 'LPCWSTR' int main(int argc, char argv[]) { // open port for I/O HANDLE h = CreateFile(argv[1],GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); if(h == INVALID_HANDLE_VALUE) { convert char* to lpcwstr PrintError("E012_Failed to open port"); can someone help? c++ windows createfile lpcwstr share|improve this question edited Jun 8 '15 at 22:40 Joseph Stine 9551921 asked Oct 13 '10 at 14:45 sebastian 53361433 add a comment| 5 Answers 5 active oldest votes up vote 7 down vote accepted It should be int main(int argc, char* argv[]) And HANDLE h = CreateFileA(argv[1],GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL); share|improve this answer answered Oct 13 '10 at 14:51 ybungalobill 37.6k1074136 1 I don't thing using the ANSI version of CreateFile is the right way to go, next thing you know and he'll start changing all the function calls to use the ANSI version. –Nikola Smiljanić Oct 13 '10 at 15:00 1 @Nikola: Of course it's the wrong way! I just think that it's not appropriate to explain the difference between char, wchat_t, TCHAR and how to write correct unicode applications to an absolute beginner. –ybungalobill Oct 13 '10 at 15:04 add a comment| up vote 85 down vote Go to the Properties for your Project and under Configuration Propert
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
Const Char Is Incompatible With Lpcwstr
the company Business Learn more about hiring developers or posting ads with us Stack Overflow argument of type "const wchar_t *" is incompatible with parameter of type "lpcstr" Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Cannot Convert From Const Char To 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 http://stackoverflow.com/questions/3924926/cannot-convert-parameter-1-from-char-to-lpcwstr 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 { 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 http://stackoverflow.com/questions/29800514/cannot-convert-argument-1-from-const-char-5-to-lpctstr 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 20:51 add a comment| 5 Answers 5 active oldest votes up vote 1 down vote accepted SetWindowTextW() takes a character pointer to the string's data where your string data consists of regular chars, but your function most likely expects a unicode string, so you cannot input string types directly. You need to use L"thisismystring" share|improve this answer edited Apr 22 '15 at 21:05 answered Apr 22 '15 at 14:22 Javia1492 493113 Can you elaborate on its degree of wrongness? What specifically is incorrect? –Javia1492 Apr 22 '15 at 20:45 @Yakk That's interesting because i've received this error multiple times in my work and have solved i
Studio Languages , Windows Desktop Development > C++ Standards, Extensions, and Interop General discussion 5 Sign in to vote Note: This is a FAQ, not a question being asked. Question https://social.msdn.microsoft.com/Forums/vstudio/en-US/c1b08c0a-a803-41c3-ac8c-84eba3be1ddb/faq-cannot-convert-from-const-char-to-lpctstr?forum=vclanguage I'm trying to compile 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' http://www.gamedev.net/topic/535404-problem-with-const-char-to-lpcwstr-conversion/ What am I doing wrong? Problem This error message means that you are trying to pass a multi-byte string (const char [12]) to a function which expects a unicode string (LPCTSTR). The LPCTSTR const char 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 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 from const char 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 MessageBoxW seen above. In case of multi-byte, the function would be MessageBoxA (ASCII). Which of these functions is actually used when you compile your application, depends on the setting described in resolution #1 above. References and recommended reads Support for Unicode Generic-Text Mappings in Tchar.h Unicode and Character Sets Co
topic ForumsMembersHelp Files Developer Journals Gallery Calendar Downloads Resources Store Classifieds Tracker Links Home For Beginners Articles All Articles Post an Article Technical Game Programming General Programming Graphics Programming and Theory DirectX and XNA OpenGL and Vulkan Multiplayer and Network Programming Artificial Intelligence Math and Physics Mobile Development Middleware, Libraries, and Tools Virtual and Augmented Reality Creative Game Design Music and Sound Visual Arts Business Breaking into the Industry Production and Management Interviews Business and Law Event Coverage Forums All Forums Technical Game Programming General Programming Graphics Programming and Theory DirectX and XNA OpenGL & Vulkan Multiplayer and Network Programming Artificial Intelligence Math and Physics Mobile & Console Development Build Systems & Source Control Middleware, Libraries, and Tools Virtual and Augmented Reality Creative Game Design Writing For Games Music and Sound Visual Arts Gallery Business Breaking into the Industry Business & Law Production & Management Community GDNet Lounge Coding Horrors Article Writing Comments, Suggestions and Ideas Your Announcements Hobby Project Classifieds Indie Project Showcase Community Developer Journals GDNet+ Subscriptions Gallery Store Classifieds Jobs Freelancers Hobby Projects Marketplace Newsletter » Home » Forums » The Technical Side » For Beginners Chat Watched Content New Content 0 Problem with const char to LPCWSTR conversion Started by TroyM88, May 18 2009 03:07 PM Old topic! Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic. You cannot reply to this topic 7 replies to this topic #1 TroyM88 Members -Reputation: 144 Like 0Likes Like Posted 18 May 2009 - 03:07 PM ok so im currently working on a game and i've been getting some strange outputs i wont copy in all my source code because there is alot and everything is set correctly.... well that i know of. error C2664: 'TextOutW' : cannot convert parameter 4 from 'const char *' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast error C2664: 'CreateWindowExW' : cannot convert parameter 3 from 'const char *' to 'LPCWSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast // this is where the compiler is taking me to for the first error message.. void CLevel::DrawScore() { HDC hdc = CGame::GetInstance().GetBackBuffer()->GetBFDC(); const int