c++ - 2 IntelliSense: argument of type "const char *" is incompatible with parameter of type "LPCWSTR" -


stackflow members ---- i'm beginner in c++ winapi --- when coding in first win32 gui, appeared errors [output] --- there recommended books advanced in c++ --- codes:

#include <windows.h> const char g_szclassname[] = ("mywindowclass");  lresult callback wndproc(hwnd hwnd, uint msg, wparam wparam, lparam lparam) {     switch(msg)    {        case wm_close:         destroywindow(hwnd);        break;         case wm_destroy:      postquitmessage(0);      break;         default:        return defwindowproc(hwnd, msg, wparam, lparam);      }      return 0;     } int winapi winmain(hinstance hinstance, hinstance hprevinstance,     lpstr lpcmdline, int ncmdshow) {     wndclassex wc;      hwnd hwnd;     msg msg;     wc.cbsize        = sizeof(wndclassex);     wc.style         = 0;       wc.lpfnwndproc   = wndproc;     wc.cbclsextra    = 0;       wc.cbwndextra    = 0;       wc.hinstance     = hinstance;       wc.hicon         = loadicon(null, idi_application);        wc.hcursor       = loadcursor(null, idc_arrow);      wc.hbrbackground = (hbrush)(color_window+1);       wc.lpszmenuname  = null;       wc.lpszclassname = (g_szclassname);       wc.hiconsm       = loadicon(null, idi_application);     if(!registerclassex(&wc))    {       messagebox(null,         l"window registration failed!",     l"error!",          mb_iconexclamation | mb_ok);       return 0;       }     // creating window        hwnd = createwindowex(         ws_ex_clientedge,        (g_szclassname),          l"the title of window",           ws_overlappedwindow,           cw_usedefault, cw_usedefault, 240, 120,        null, null, hinstance, null);     if(hwnd == null)    {       messagebox(null,          l"window creation failed!",         l"error!",         mb_iconexclamation | mb_ok);          return 0;       }     showwindow(hwnd, ncmdshow);       updatewindow(hwnd);     // step 3: message loop         while(getmessage(&msg, null, 0, 0) > 0)    {          translatemessage(&msg);            dispatchmessage(&msg);      }       return msg.wparam;      } 

output :

    3   intellisense: argument of type "const char *" incompatible parameter of type "lpcwstr"  c:\users\youssef\documents\visual studio 2012\projects\win32project2\win32project2\win32project2.cpp    46  2   win32project2     2   intellisense: value of type "const char *" cannot assigned entity of type "lpcwstr"  c:\users\youssef\documents\visual studio 2012\projects\win32project2\win32project2\win32project2.cpp    34  19  win32project2 error   1   error c1010: unexpected end of file while looking precompiled header. did forget add '#include "stdafx.h"' source?   c:\users\youssef\documents\visual studio 2012\projects\win32project2\win32project2\win32project2.cpp    65  1   win32project2 

the compilation issue you're having has string types , windows programs.

note there 2 character set "build types" windows program. first mbcs , second unicode. default (assuming you're using visual studio), build type unicode, meaning various windows api functions process wide strings, not char or char-based strings.

the easiest solution problem use tchar character arrays , _t() macro string literals meant sent , received windows api functions. ensure app compile unicode, mbcs (although mbcs programs considered obsolete in day , age).

this line:

 wc.lpszclassname = (g_szclassname);   

gives issue, since compiling unicode application, , member of wndclassex takes lpctstr (a pointer tchar), not const char *.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633577%28v=vs.85%29.aspx

so problem,

const char g_szclassname[] = ("mywindowclass"); 

the change should be:

#include <tchar.h> // in case isn't included  //... tchar g_szclassname[] = _t("mywindowclass"); 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -