Index: trunk/src/comdlg32/comdlg32.cpp
===================================================================
--- trunk/src/comdlg32/comdlg32.cpp	(revision 180)
+++ trunk/src/comdlg32/comdlg32.cpp	(revision 181)
@@ -1,3 +1,3 @@
-/* $Id: comdlg32.cpp,v 1.5 1999-06-23 16:39:29 achimha Exp $ */
+/* $Id: comdlg32.cpp,v 1.6 1999-06-24 16:54:24 achimha Exp $ */
 
 /*
@@ -280,4 +280,7 @@
     FreeAsciiString((char*)asciicf.lpTemplateName);
 
+  // copy back fields
+  lpcf->Flags = asciicf.Flags;
+
   return bResult;
 }
@@ -394,4 +397,7 @@
   }
 
+  // copy back fields
+  lpfr->Flags = fr.Flags;
+
   return bResult;
 }
@@ -456,4 +462,5 @@
   char*           szFile;
   char*           szFileTitle;
+  char*           szCustFilter;
   BOOL            bResult;
 
@@ -475,7 +482,4 @@
     ofn.lpstrFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrFilter);
 
-  if (lpofn->lpstrCustomFilter != NULL)
-    ofn.lpstrCustomFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrCustomFilter);
-
   if (lpofn->lpstrInitialDir != NULL)
     ofn.lpstrInitialDir = UnicodeToAsciiString((WCHAR*)lpofn->lpstrInitialDir);
@@ -488,7 +492,38 @@
 
   szFile             = (char*)malloc(lpofn->nMaxFile);
-  szFileTitle        = (char*)malloc(lpofn->nMaxFileTitle);
-  ofn.lpstrFile      = szFile;
-  ofn.lpstrFileTitle = szFileTitle;
+  szFile[0]          = 0;
+
+  if (*lpofn->lpstrFile != 0)
+    UnicodeToAscii(lpofn->lpstrFile,
+                   szFile);
+
+  if (lpofn->lpstrFileTitle != NULL)
+  {
+    szFileTitle        = (char*)malloc(lpofn->nMaxFileTitle);
+    szFileTitle[0]     = 0;
+
+    if (*lpofn->lpstrFileTitle != 0)
+      UnicodeToAscii(lpofn->lpstrFileTitle,
+                     szFileTitle);
+  }
+  else
+    szFileTitle = NULL;
+
+  if (lpofn->lpstrCustomFilter != NULL)
+  {
+    szCustFilter       = (char*)malloc(lpofn->nMaxCustFilter);
+    szCustFilter[0]    = 0;
+
+
+    if (*lpofn->lpstrCustomFilter != 0)
+       UnicodeToAscii(lpofn->lpstrCustomFilter,
+                      szCustFilter);
+  }
+  else
+    szCustFilter = NULL;
+
+  ofn.lpstrFile         = szFile;
+  ofn.lpstrFileTitle    = szFileTitle;
+  ofn.lpstrCustomFilter = szCustFilter;
 
   COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC)
@@ -498,5 +533,4 @@
   if (ofn.lpTemplateName    != NULL) FreeAsciiString((char*)ofn.lpTemplateName);
   if (ofn.lpstrFilter       != NULL) FreeAsciiString((char*)ofn.lpstrFilter);
-  if (ofn.lpstrCustomFilter != NULL) FreeAsciiString((char*)ofn.lpstrCustomFilter);
   if (ofn.lpstrInitialDir   != NULL) FreeAsciiString((char*)ofn.lpstrInitialDir);
   if (ofn.lpstrTitle        != NULL) FreeAsciiString((char*)ofn.lpstrTitle);
@@ -504,14 +538,27 @@
 
   // transform back the result
-  AsciiToUnicodeN(ofn.lpstrFile,
-                  lpofn->lpstrFile,
-                  lpofn->nMaxFile);
-
-  AsciiToUnicodeN(ofn.lpstrFileTitle,
-                  lpofn->lpstrFileTitle,
-                  lpofn->nMaxFileTitle);
-
+  AsciiToUnicode(ofn.lpstrFile,
+                 lpofn->lpstrFile);
   free(szFile);
-  free(szFileTitle);
+
+  if (lpofn->lpstrFileTitle != NULL)
+  {
+    AsciiToUnicode(ofn.lpstrFileTitle,
+                   lpofn->lpstrFileTitle);
+    free(szFileTitle);
+  }
+
+  if (lpofn->lpstrCustomFilter != NULL)
+  {
+    AsciiToUnicode(ofn.lpstrCustomFilter,
+                   lpofn->lpstrCustomFilter);
+    free(szCustFilter);
+  }
+
+  // copy over some altered flags
+  lpofn->nFilterIndex   = ofn.nFilterIndex;
+  lpofn->Flags          = ofn.Flags;
+  lpofn->nFileOffset    = ofn.nFileOffset;
+  lpofn->nFileExtension = ofn.nFileExtension;
 
   return bResult;
@@ -537,4 +584,5 @@
   char*           szFile;
   char*           szFileTitle;
+  char*           szCustFilter;
   BOOL            bResult;
 
@@ -556,7 +604,4 @@
     ofn.lpstrFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrFilter);
 
-  if (lpofn->lpstrCustomFilter != NULL)
-    ofn.lpstrCustomFilter = UnicodeToAsciiString((WCHAR*)lpofn->lpstrCustomFilter);
-
   if (lpofn->lpstrInitialDir != NULL)
     ofn.lpstrInitialDir = UnicodeToAsciiString((WCHAR*)lpofn->lpstrInitialDir);
@@ -568,24 +613,39 @@
     ofn.lpstrDefExt = UnicodeToAsciiString((WCHAR*)lpofn->lpstrDefExt);
 
-  // prepare szFile and szFileTitle
   szFile             = (char*)malloc(lpofn->nMaxFile);
-  szFileTitle        = (char*)malloc(lpofn->nMaxFileTitle);
-
-  if (*lpofn->lpstrFile == 0)
-    szFile[0] = 0;
-  else
-    UnicodeToAsciiN(lpofn->lpstrFile,
-                    szFile,
-                    lpofn->nMaxFile);
-
-  if (*lpofn->lpstrFileTitle == 0)
-    szFileTitle[0] = 0;
-  else
-    UnicodeToAsciiN(lpofn->lpstrFileTitle,
-                    szFileTitle,
-                    lpofn->nMaxFileTitle);
-
-  ofn.lpstrFile      = szFile;
-  ofn.lpstrFileTitle = szFileTitle;
+  szFile[0]          = 0;
+
+  if (*lpofn->lpstrFile != 0)
+    UnicodeToAscii(lpofn->lpstrFile,
+                   szFile);
+
+  if (lpofn->lpstrFileTitle != NULL)
+  {
+    szFileTitle        = (char*)malloc(lpofn->nMaxFileTitle);
+    szFileTitle[0]     = 0;
+
+    if (*lpofn->lpstrFileTitle != 0)
+      UnicodeToAscii(lpofn->lpstrFileTitle,
+                     szFileTitle);
+  }
+  else
+    szFileTitle = NULL;
+
+  if (lpofn->lpstrCustomFilter != NULL)
+  {
+    szCustFilter       = (char*)malloc(lpofn->nMaxCustFilter);
+    szCustFilter[0]    = 0;
+
+
+    if (*lpofn->lpstrCustomFilter != 0)
+       UnicodeToAscii(lpofn->lpstrCustomFilter,
+                      szCustFilter);
+  }
+  else
+    szCustFilter = NULL;
+
+  ofn.lpstrFile         = szFile;
+  ofn.lpstrFileTitle    = szFileTitle;
+  ofn.lpstrCustomFilter = szCustFilter;
 
   COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC)
@@ -595,5 +655,4 @@
   if (ofn.lpTemplateName    != NULL) FreeAsciiString((char*)ofn.lpTemplateName);
   if (ofn.lpstrFilter       != NULL) FreeAsciiString((char*)ofn.lpstrFilter);
-  if (ofn.lpstrCustomFilter != NULL) FreeAsciiString((char*)ofn.lpstrCustomFilter);
   if (ofn.lpstrInitialDir   != NULL) FreeAsciiString((char*)ofn.lpstrInitialDir);
   if (ofn.lpstrTitle        != NULL) FreeAsciiString((char*)ofn.lpstrTitle);
@@ -601,21 +660,31 @@
 
   // transform back the result
+  AsciiToUnicode(ofn.lpstrFile,
+                 lpofn->lpstrFile);
+  free(szFile);
+
+  if (lpofn->lpstrFileTitle != NULL)
+  {
+    AsciiToUnicode(ofn.lpstrFileTitle,
+                   lpofn->lpstrFileTitle);
+    free(szFileTitle);
+  }
+
+  if (lpofn->lpstrCustomFilter != NULL)
+  {
+    AsciiToUnicode(ofn.lpstrCustomFilter,
+                   lpofn->lpstrCustomFilter);
+    free(szCustFilter);
+  }
+
+  // copy over some altered flags
+  lpofn->nFilterIndex   = ofn.nFilterIndex;
+  lpofn->Flags          = ofn.Flags;
   lpofn->nFileOffset    = ofn.nFileOffset;
   lpofn->nFileExtension = ofn.nFileExtension;
-  // @@@PH: remark - are these all required pass-back fields ?
-
-  AsciiToUnicodeN(ofn.lpstrFile,
-                  lpofn->lpstrFile,
-                  lpofn->nMaxFile);
-
-  AsciiToUnicodeN(ofn.lpstrFileTitle,
-                  lpofn->lpstrFileTitle,
-                  lpofn->nMaxFileTitle);
-
-  free(szFile);
-  free(szFileTitle);
 
   return bResult;
 }
+
 
 /*****************************************************************************
@@ -693,4 +762,5 @@
 
   // copy back result
+  lppd->Flags     = pd.Flags;
   lppd->nFromPage = pd.nFromPage;
   lppd->nToPage   = pd.nToPage;
@@ -794,6 +864,8 @@
   }
 
+  // copy back fields
+  lpfr->Flags = fr.Flags;
+
   return bResult;
-
 }
 
