c++ - problem initializing global variables -
i have begun learning win32 api using tutorial:
http://www.winprog.org/tutorial/ (though i'm using c++, not c in tutorial) i'm experimenting "edit box"-function i'm trying compare text written in edit box line of characters. code:
#define idc_main_edit 101
code:
case wm_create: { hfont hfdefault; hwnd hedit; hedit = createwindowex(ws_ex_clientedge, "edit", "", ws_child | ws_visible | ws_vscroll | ws_hscroll | es_multiline | es_autovscroll | es_autohscroll, 0, 0, 100, 100, hwnd, (hmenu)idc_main_edit, getmodulehandle(null), null); if(hedit == null) messagebox(hwnd, "could not create edit box.", "error", mb_ok | mb_iconerror); hfdefault = getstockobject(default_gui_font); sendmessage(hedit, wm_setfont, (wparam)hfdefault, makelparam(false, 0)); } break; case wm_size: { hwnd hedit; rect rcclient; getclientrect(hwnd, &rcclient); hedit = getdlgitem(hwnd, idc_main_edit); setwindowpos(hedit, null, 0, 0, rcclient.right, rcclient.bottom, swp_nozorder); } break;
code:
bool comparison (hwnd hedit) { lpwstr psztext; dword dwtextlength; dword dwbuffersize; dwtextlength = getwindowtextlength(hedit); dwbuffersize = dwtextlength + 1; getwindowtext(hedit, psztext, dwbuffersize); if(psztext == text("3")) { return true; } else { return false; } }
the problem when call "comparison"-function psztext , hedit aren't initialized. why psztext isn't , i've tried using new/delete fix it, don't work. have no clue hedit. perhaps using getwindowtext-function wrong? warnings code:
warning c4700: uninitialized local variable 'psztext' used warning c4700: uninitialized local variable 'hedit' used
run-time check failure (appear when i'm using function, , 1 of them) code:
run-time check failure #3 - variable 'hedit' being used without being initializ
psztext
pointer type. you'need allocate memory before use it.
do this:
wchar_t *psztext = new wchar_t[size]; //calculate or guess `size`
Comments
Post a Comment