c++ - Call to GetOpenFileNameA causes common dialog error 2 -
i'm trying open dialog box using getopenfilenamea. however, dialog not open. instead, nice commdlgerror 2. searching google , stackoverflow error did not produce helpful results.
confusingly, code works on school computer uses visual studio, albeit different version.
note: variables not declared in block of code "global" variables accessible within main code module.
void getinputfile() { char szfilenamein[max_path]; char szfilenameout[max_path]; // input file name openfilename ofn; zeromemory(&finputpath, sizeof(finputpath)); zeromemory(&ofn, sizeof(ofn)); ofn.lstructsize = sizeof(ofn); ofn.hwndowner = null; ofn.lpstrfilter = lpwstr("any file\0*.*\0"); ofn.lpstrfile = lpwstr(finputpath); ofn.nmaxfile = max_path; ofn.lpstrfiletitle = lpwstr(szfilenamein); ofn.nmaxfiletitle = max_path; ofn.lpstrtitle = lpwstr("select input file"); ofn.flags = ofn_dontaddtorecent | ofn_filemustexist; if (getopenfilenamea(lpopenfilenamea(&ofn))) // user selected input file { } else { // error tchar error[max_loadstring]; wsprintf(error,text("%i"),commdlgextendederror()); messagebox(null,error,text("error"),mb_ok); } }
those awful (lpwstr) casts tell me compiling unicode defined, openfilename struct using openfilenamew; given using getopenfilenamea, have use openfilenamea (or use straight getopenfilename wide strings).
(and remember that, rule of thumb, if have cast pointers to/from different void * , similar, doing wrong; adding pointer casts silence compiler, not make error go away)
Comments
Post a Comment