Error C2440 Cannot Convert From Const Char * To Lpstr
Contents |
work\jyfjtjyulkuyl\jyfjtjyulkuyl\bdfbdh.cpp(26) : error C2440: '=' : cannot convert from 'const char *' to 'LPCWSTR' heres the code: cannot convert parameter from const char to lpcwstr #include
Cannot Convert Parameter 1 From Const Char * To Lpcwstr
Simple Window"; LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE cannot convert from const char to lpctstr hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG Msg; HWND hWnd; WNDCLASSEX WndClsEx; // Create the application window WndClsEx.cbSize = sizeof(WNDCLASSEX); WndClsEx.style = CS_HREDRAW | CS_VREDRAW; WndClsEx.lpfnWndProc = WndProcedure; WndClsEx.cbClsExtra a value of type "const char *" cannot be assigned to an entity of type "lpcwstr" = 0; WndClsEx.cbWndExtra = 0; WndClsEx.hIcon = LoadIcon(NULL, IDI_APPLICATION); WndClsEx.hCursor = LoadCursor(NULL, IDC_ARROW); WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); WndClsEx.lpszMenuName = NULL; WndClsEx.lpszClassName = ClsName; WndClsEx.hInstance = hInstance; WndClsEx.hIconSm = LoadIcon(NULL, IDI_APPLICATION); // Register the application RegisterClassEx(&WndClsEx); // Create the window object hWnd = CreateWindow(ClsName, WndName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); // Find out if the window was
Intellisense: Argument Of Type "const Char *" Is Incompatible With Parameter Of Type "lpcwstr"
created if( !hWnd ) // If the window was not created, return 0; // stop the application // Display the window to the user ShowWindow(hWnd, SW_SHOWNORMAL); UpdateWindow(hWnd); // Decode and treat the messages // as long as the application is running while( GetMessage(&Msg, NULL, 0, 0) ) { TranslateMessage(&Msg); DispatchMessage(&Msg); } return Msg.wParam; } LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) { switch(Msg) { // If the user wants to close the application case WM_DESTROY: // then close it PostQuitMessage(WM_QUIT); break; default: // Process the left-over messages return DefWindowProc(hWnd, Msg, wParam, lParam); } // If something was not done, let it go return 0; } What am i doing wrong!!!!!!!!!!!!!!!!!!!! Nov 4, 2008 at 9:05pm UTC guestgulkan (2942) LPCWSTR = Long Pointer Constant WIDE String In other words a pointer to a UNICODE string is expected. const char *WndName = "A Simple Window"; This is a normal 8 bit ascii string. With Microsoft Visual Studio, the default program setup is for the USE of UNICODE string - hence the
[7]' to 'LPCWSTR' Results 1 to 4 of 4 Thread: error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR' Thread Tools Show Printable Version Email this Page… Search Thread Advanced Search Rate This Thread Current Rating Excellent wndclassex Good Average Bad Terrible Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 12-20-2010,05:49 AM #1 brislin View Profile View Forum Posts Registered User Join Date Jul 2005 Location Independence Mo. Posts 380 error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR' I was follow the WinApi demo in opengl and got this error "error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR" After doing a google I found http://www.cplusplus.com/forum/windows/5368/ it had to do with if you using unicode the fix i found was to change the "char" to "wchar_t". before Code: BOOL createGLWindow(char *title, int width, int height, int bits) { } change to this Code: BOOL createGLWindow(wchar_t *title, int width, int height, int bits) { } and when you go to use you string Code: wc.lpszClassName = L"OpenGL"; I just thought i would post this just incase some else had this problem if some one http://www.3dbuzz.com/forum/threads/186287-error-C2440-cannot-convert-from-const-char-7-to-LPCWSTR else could a bettter explanation of what the problem was and how to fix it would be nice Reply With Quote 12-20-2010,07:11 AM #2 brislin View Profile View Forum Posts Registered User Join Date Jul 2005 Location Independence Mo. Posts 380 Reply With Quote 12-20-2010,12:08 PM #3 ComicSansMS View Profile View Forum Posts Visit Homepage Most Horrible Font Ever Join Date Jun 2003 Location Trier, Germany Posts 1,350 i gave a somewhat lengthy explanation of what unicode is all about back in this thread (you'll have to scroll a little). the whole topic is quite exhausting, so feel free to ask if you have questions left. edit: just noticed: seems i didn't know about TCHAR back then, a typedef from windows.h that automatically resolves to char or wchar_t, so you won't need to do that manually. Last edited by ComicSansMS; 12-20-2010 at 12:11 PM. A Pageant of the Bizarre Reply With Quote 12-21-2010,12:20 PM #4 Notsosuperhero View Profile View Forum Posts CodeGuru C++ Guru Join Date Jun 2005 Location NY Posts 1,374 Always keep in mind when using WinAPI if you see an string conversion error with a type that has W in it, it means you trying to use an ANSI string with a UNICODE function. Many functions in WinAPI have two versions ANSI(which will append 'A' to the end of the function) or UNICODE(which appends 'W' to
to 'LPCW Page 1 of 1 New Topic/Question Reply 3 Replies - 13190 Views - Last Post: 11 September 2007 - 06:55 PM http://www.dreamincode.net/forums/topic/33033-cannot-convert-parameter-2-from-const-char-32-to-lpcw/ Rate Topic: #1 ModestBigferd New D.I.C Head Reputation: 0 Posts: 7 Joined: 06-September 07 cannot convert parameter 2 from 'const char [32]' to 'LPCW Posted 11 September 2007 - 02:23 AM I could very well be losing it. Right now I'm learning some basic windows programming with a focus on game design with the book const char "Tricks of the Game Programming Gurus". Anyway, as I go through the different elements I tend to keep working in the same project just adding on and commenting out things as I learn. This can get kinda messy as you can imagine so I went to start a new project and just copy and paste the skeleton elements. from const char What's messing with my head is that things in the new project WON'T work while the EXACT SAME things in the old one work fine. Now, I've gone through and double-checked everything about a hundred times and I can't figure it out. My Includes are all the same, as well as including the "WinMM.lib" file in my project and project folder. Here is the code for both files starting with the GOOD one: // WNDCLASSEX - A complete windows program #define WIN32_LEAN_AND_MEAN // INCLUDES ///////////////////////////////////////////////// #include