The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on February 06, 2008, 07:58:00 AM

Title: GetOpenFileName crash, why?
Post by: Farabi on February 06, 2008, 07:58:00 AM
I dont know what is wrong, thanks for point me my mistake. I dont know why but it is working befor.



GetFileName proc uses esi hParent:DWORD,lpTitle:DWORD,lpFilter:DWORD
LOCAL ofn         :  OPENFILENAME ; structure

   mov ofn.lStructSize,        sizeof OPENFILENAME
   push 0
   pop ofn.hWndOwner
   push 0
   pop ofn.hInstance
   push lpFilter
   pop ofn.lpstrFilter
   push offset szFileName
   pop ofn.lpstrFile
   mov ofn.nMaxFile,           sizeof szFileName
   push lpTitle
   pop ofn.lpstrTitle
   mov ofn.Flags,              OFN_EXPLORER or OFN_FILEMUSTEXIST or \
                               OFN_LONGNAMES

   invoke GetOpenFileName,ADDR ofn
   ret

GetFileName endp

fOpenFileDialog proc hWnd:dword,lpszTitleO:dword,lpszFilterO:dword

   
           invoke memfill,ADDR szFileName,length szFileName,0
           invoke GetFileName,hWnd, lpszTitleO, lpszFilterO
           
           .if eax!=0
           lea eax,szFileName
           .endif
ret
fOpenFileDialog endp


I call it like this


.elseif uMsg==WM_COMMAND

.if wParam==101
invoke fOpenFileDialog,0,CADD("Pilih berkas gambar:"),addr filt
cmp eax,0
jz @F
invoke FaceDetect,eax
@@:
Title: Re: GetOpenFileName crash, why?
Post by: ToutEnMasm on February 06, 2008, 02:05:26 PM
Hello,
Without many search (parameters of the function are not shown),I see that the structure is in the stack (local variables).
Common mistake is to forget the initialisation at zero of all the structure before full it with useful data.
a RtlZeroMemory of all the structure seem needed

Quote
OPENFILENAMEA   STRUCT
   lStructSize DWORD ?
   hwndOwner DWORD ?
   hInstance DWORD ?
   lpstrFilter DWORD ?
   lpstrCustomFilter DWORD ?
   nMaxCustFilter DWORD ?
   nFilterIndex DWORD ?
   lpstrFile DWORD ?
   nMaxFile DWORD ?
   lpstrFileTitle DWORD ?
   nMaxFileTitle DWORD ?
   lpstrInitialDir DWORD ?
   lpstrTitle DWORD ?
   Flags DWORD ?
   nFileOffset WORD ?
   nFileExtension WORD ?
   lpstrDefExt DWORD ?
   lCustData DWORD ?
   lpfnHook DWORD ?
   lpTemplateName DWORD ?
IFDEF _MAC
   lpEditInfo DWORD ?
   lpstrPrompt DWORD ?
ENDIF
IF COMPARE(_WIN32_WINNT,GE,00500h)
   pvReserved DWORD ?
   dwReserved DWORD ?
   FlagsEx DWORD ?
ENDIF ; (_WIN32_WINNT >= 0x0500)
OPENFILENAMEA      ENDS