Subj : Re: Common Dialog Memory Leak? To : borland.public.cpp.borlandcpp From : Bob Gonder Date : Tue Jun 07 2005 09:22 am akuma wrote: >I'm using Windows XP and writing a file to open text file with the >GetOpenFileName API funciton. Everytime when call to the common dialog >function, it spends about 2 seconds to show it and the memory required by my >program increases serval KB each time. The following is the code: > >OPENFILENAME fn; > > ZeroMemory(&fn, sizeof(fn)); > fn.lStructSize = sizeof(fn); > > fn.lpstrFilter = "Text files\0*.txt\0\0"; > fn.lpstrInitialDir = "C:\\Windows\0"; > fn.nMaxFile = 256; > fn.hwndOwner = GetFocus(); > fn.lpstrTitle = "Open file\0"; > fn.nMaxFileTitle = 256; > fn.nFilterIndex = 1; > fn.FlagsEx = OFN_EX_NOPLACESBAR; > > fn.Flags = Dlg->Flags | OFN_ENABLEHOOK | OFN_EXPLORER; > > GetOpenFileName((OPENFILENAME*)&fn); > >Please help me to optimize the code, so that it can display the dialog more >efficiently with the explorer style. Does it even work? I don't see lpstrFile member being allocated or set. You say lpstrFile is 256 bytes (nMaxFile), but don't provide it? You also fail to provide for lpstrFileTitle, even though you claim it is 256 bytes (nMaxFileTitle) ? You specify OFN_ENABLEHOOK but don't provide a hook (lpfnHook) ? Also, you make no mention of what the values are for Dlg->Flags ? These are the flags I use (XP Win32) fn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_LONGNAMES | OFN_NOCHANGEDIR; See this link about the use of OFN_EXPLORER. Note that explorer is the default interface whether you provide this flag or not. http://tinyurl.com/5wchk Long link may wrap http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/commondialogboxlibrary/commondialogboxreference/commondialogboxstructures/openfilename.asp .