Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Application crash with unicode version of GetOpenFileName function

Hi,

When I run the below function Open file dialog opens but when I select the filter listbox, my application gets crashed in unicode version of my application.

My application works fine with non UNICODE setting but only crashes when UNICODE option is set.

Please let me know if there are any errors in below code.


[italic]BOOL GetFileName (HWND hOwner,
UINT titleid,
UINT filterid,
ULONG flags,
TCHAR* szExt,
TCHAR* szNewFile,
BOOL bSave,
UINT helpid)
{
OPENFILENAME ofn;
TCHAR szFileTitle[64] = NULLSTR;
TCHAR szFilter[256] = NULLSTR;
TCHAR szFile[256] = NULLSTR;
TCHAR szDefExt[10] = NULLSTR;
TCHAR szDefDir[256] = NULLSTR;
TCHAR chReplace;
TCHAR title[50];
UINT i;
BOOL retval;


/* If there is a file, use it for default loading */
if (_tcslen(szNewFile)) {
file_GPath(szNewFile,256,szDefDir);
file_GName(szNewFile,256,szFile);

if (szFile) {
file_GExt(szNewFile,10,szDefExt);
if (szExt) {
_tcscat(szFile,_T("."));
_tcscat(szFile,szDefExt);
}
}
}


_tcscpy(szFilter,_T("My Apps (*.TXT)|*.txt|"));


/* Get delimiter char and replace with terminator */
chReplace = szFilter[_tcslen(szFilter)-1];
for (i = 0; szFilter[i] != ''; i++) {
if (szFilter[i] == chReplace) {
szFilter[i] = '';
}
}

/* Initialize structure */
memset(&ofn,0,sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hOwner;
ofn.hInstance = theRE.Inst;
ofn.lpstrFilter =szFilter;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 256;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = sizeof(szFileTitle)/sizeof(TCHAR);
ofn.lpstrInitialDir = szDefDir;
ofn.lpstrDefExt = szExt;
ofn.lpstrTitle = _T("Open Dialog");

ofn.Flags = flags | OFN_ENABLEHOOK | OFN_HIDEREADONLY;


#ifdef WIN32
ofn.lpfnHook = (CDHOOKFUNC)ui_CommDlgHookFunc;
#else
ofn.lpfnHook = (CDHOOKFUNC)MakeProcInstance((FARPROC)ui_CommDlgHookFunc,
theRE.m_hInstance);
#endif
/* Go to the user */

if (bSave) {
ofn.Flags |= OFN_OVERWRITEPROMPT;
retval = GetSaveFileName(&ofn);
} else {
retval = GetOpenFileName(&ofn);
}

#ifndef WIN32
FreeProcInstance((FARPROC)ofn.lpfnHook);
#endif

if (!retval) {
return(FALSE);
}

return(TRUE);
}



Here is an implementation of hook function:


BOOL EXPORT CALLBACK ui_CommDlgHookFunc (HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{


switch (msg) {
case WM_INITDIALOG:
#ifndef UNIX
# if _MSC_VER < 1300



if (theRE.m_bUse3d) {
Ctl3dSubclassDlg(hwnd,CTL3D_ALL);
}
# endif
#endif


break;

default:
break;
}

return(FALSE);
}[/italic]






Regards,
Dayakar



Sign In or Register to comment.