flat assembler
Message board for the users of flat assembler.

Index > Windows > GetSaveFileName problems

Author
Thread Post new topic Reply to topic
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 19 Aug 2007, 13:52
Hello,

I'm having some problems with GetSaveFileName.

Why does the following work:
Code:
.data
ofn             OPENFILENAME
lpFilter        db '*.txt',0,'*.txt',0,0
lpTitle         db 'Save',0
lpFileName     db MAX_PATH dup (?)

.code
start:  call    savedlg
     invoke  MessageBox,0,[ofn.lpstrFile],'Filename',0
 invoke  ExitProcess,0

proc       savedlg
     mov     [ofn.lStructSize],sizeof.OPENFILENAME
       mov     [ofn.lpstrFilter],lpFilter
  mov     [ofn.lpstrDefExt],lpFilter
  mov     [ofn.lpstrFile],lpFileName
  mov     [ofn.nMaxFile],MAX_PATH
     mov     [ofn.lpstrTitle],lpTitle
    mov     [ofn.Flags],OFN_EXPLORER or OFN_LONGNAMES or OFN_OVERWRITEPROMPT
    invoke  GetSaveFileName,ofn
 test    eax,eax
     jne     @f
  invoke  MessageBox,0,'Error','Error',0
@@:   ret
endp
    


while this doesn't (garbage is displayed instead of the filename):
Code:
.data
ofn           OPENFILENAME
lpFilter        db '*.txt',0,'*.txt',0,0
lpTitle         db 'Save',0

.code
start:        call    savedlg
     invoke  MessageBox,0,[ofn.lpstrFile],'Filename',0
 invoke  ExitProcess,0

proc       savedlg
local        lpFileName[MAX_PATH]:BYTE
       mov     [ofn.lStructSize],sizeof.OPENFILENAME
       mov     [ofn.lpstrFilter],lpFilter
  mov     [ofn.lpstrDefExt],lpFilter
  lea     eax,[lpFileName]
    mov     [ofn.lpstrFile],eax
 mov     [ofn.nMaxFile],MAX_PATH
     mov     [ofn.lpstrTitle],lpTitle
    mov     [ofn.Flags],OFN_EXPLORER or OFN_LONGNAMES or OFN_OVERWRITEPROMPT
    invoke  GetSaveFileName,ofn
 test    eax,eax
     jne     @f
  invoke  MessageBox,0,'Error','Error',0
@@:   ret
endp
    



Also, why doesn't that work (no filename is displayed)? I noticed 'pofn' get assembled in 19 dwords instead of 20. Why's that?
Code:
.data
lpFilter   db '*.txt',0,'*.txt',0,0
lpTitle         db 'Save',0
lpFileName     db MAX_PATH dup (?)
pofn             OPENFILENAME sizeof.OPENFILENAME,0,0,lpFilter,0,0,0,lpFileName,MAX_PATH,0,0,0,lpTitle,OFN_EXPLORER or OFN_LONGNAMES or OFN_OVERWRITEPROMPT,0,0,lpFilter,0,0,0

.code
start:        call    savedlg
     invoke  MessageBox,0,[ofn.lpstrFile],'Filename',0
 invoke  ExitProcess,0

proc       savedlg
     invoke  GetSaveFileName,pofn
        test    eax,eax
     jne     @f
  invoke  MessageBox,0,'Error','Error',0
@@:   ret
endp
    


Thanks for your help.
Post 19 Aug 2007, 13:52
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 244
Location: US
Yardman 19 Aug 2007, 14:47
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:49; edited 1 time in total
Post 19 Aug 2007, 14:47
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 20 Aug 2007, 05:59
Maybe it's because ofn.lpstrFile (a global value) points to lpFileName (a local array)?
I tried to use lstrcpy to copy ofn.lpstrFile to an external buffer and it worked.
The only explanation is that local memory is freed when returning from a procedure. I would appreciate some confirmations and clarifications on this one from you guys.

Code:
.data
szBuffer     db MAX_PATH dup (?)
ofn              OPENFILENAME
lpFilter        db '*.txt',0,'*.txt',0,0
lpTitle         db 'Save',0


.code
start:    call    savedlg
     invoke  MessageBox,0,szBuffer,'Filename',0
        invoke  ExitProcess,0

proc       savedlg
local        lpFileName[MAX_PATH]:BYTE

   mov     [ofn.lStructSize],sizeof.OPENFILENAME
       mov     [ofn.lpstrFilter],lpFilter
  mov     [ofn.lpstrDefExt],lpFilter
  lea     eax,[lpFileName]
    mov     [ofn.lpstrFile],eax
 mov     [ofn.nMaxFile],MAX_PATH
     mov     [ofn.lpstrTitle],lpTitle
    mov     [ofn.Flags],OFN_EXPLORER or OFN_LONGNAMES or OFN_OVERWRITEPROMPT
    invoke  GetSaveFileName,ofn
 test    eax,eax
     jne     @f
  invoke  MessageBox,0,'Error','Error',0
@@:   invoke  lstrcpy,szBuffer,[ofn.lpstrFile]
    ret
endp
    
Post 20 Aug 2007, 05:59
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.