flat assembler
Message board for the users of flat assembler.

Index > Windows > How to optimize GetSave/OpenFileName

Author
Thread Post new topic Reply to topic
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Hi,

I'am writing a program which using GetOpenFileName and GetSaveFileName.
They geting OPENFILENAME structure as a parameter, but only some fields of this structure are diffent for Save/Open procedure, so I tried to optimize code, by writing additional proc. which setting up parameters which are same in calling both API's functions. It looks like follows:
Code:
proc    SET_OPENFILENAME Parent, Instance, pFilter, pFileName, pTitle, pDefExt, pofn
        MOV [pofn.lStructSize], sizeof.OPENFILENAME
        MOV [pofn.hwndOwner], Parent
        MOV [pofn.hInstance], Instance
        MOV [pofn.lpstrFilter], pFilter
        MOV [pofn.lpstrCustomFilter], 0
        MOV [pofn.nMaxCustFilter], 0
        MOV [pofn.lpstrFile], pFileName
        MOV [pofn.nMaxFile], MAX_PATH
        MOV [pofn.lpstrFileTitle], 0h
        MOV [pofn.nMaxTitle], 0h
        MOV [pofn.lpstrInitialDir], 0h
        MOV [pofn.lpstrTitle], pTitle
        MOV [pofn.lpstrDefExt], pDefExt
        MOV [pofn.lpTemplateName], 0h
        ret
endp

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;       OPEN FILE DIALOG
proc    OpenFileDialog Parent, Instance, pFilter, pFileName, pTitle, pDefExt
        local ofn:OPENFILENAME
        invoke  SET_OPENFILENAME, Parent, Instance, pFilter, pFileName, pTitle, pDefExt, ofn
        MOV     [ofn.Flag], OFN_EXPLORER+OFN_FILEMUSTEXIST+OFN_LONGNAMES+OFN_HIDEREADONLY
        invoke  GetOpenFileName, OFN
        ret
endp      

Parameters starting with 'p' are pointers (addresses) to values, all the rest are values of variables. But I getting error messages when trying to compile it. Can somebody tell me why (I'm new in FASM - I know how to do it in HLL).

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 03 Apr 2006, 22:11
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
you can write such macro:
macro FillOpenFileNameStruct _Parent,... {
push 0 ; lpTemplateName
push _DefExt
...
push _Parent
push sizeof.OPENFILENAME
}
- it will create this filled structure in stack. pointer to it - esp
if you plan to push some after it you have to preserve pointer in another register or check offset by yourself.
after calling function you can free it with add esp,[esp]
anyway if you will use stdcall you will do some pushes, also call/ret will cost some.
regards!


Description:
Download
Filename: openfilename..1.zip
Filesize: 2 KB
Downloaded: 59 Time(s)

Post 04 Apr 2006, 05:42
View user's profile Send private message Visit poster's website Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1608
Location: Ukraine
shoorick
walking your source:
you can use such subroutine, but:
1. if you pass pointer to your structure you have to get it into register, eg. edx and use offset with it:
mov edx,[pofn]
mov [edx + OPENFILENAME.lStructSize],sizeof.OPENFILENAME
...
2. to get pointer to the local variable you have explicitlely load it,
eg.:
lea ecx,[ofn]

3.invoke will do "call [proc]", but you need "call proc" - this available via "stdcall" (fasm is not masm), eg.:
lea ecx,[ofn]
stdcall SET_OPENFILENAME,0,[hWnd],pFile,...,ecx

regards!
Post 04 Apr 2006, 07:10
View user's profile Send private message Visit poster's website Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
my code:

Code:
  szFilter              db "Executable Files",0,"*.exe",0,0
  szTitle               db "Select file",0

  proc  _openfile uses ebx esi edi, lpWnd,lpTargetPath,lpFilter,lpTitle
        local   ofn:OPENFILENAME

        lea     edi,[ofn]
        mov     ecx,sizeof.OPENFILENAME
        xor     al,al
        rep     stosb

        lea     edi,[ofn]
        mov     [edi+OPENFILENAME.lStructSize],sizeof.OPENFILENAME
        m2m     [edi+OPENFILENAME.hwndOwner],[lpWnd]
        m2m     [edi+OPENFILENAME.hInstance],[hInstance]
        m2m     [edi+OPENFILENAME.lpstrFilter],[lpFilter]
        mov     [edi+OPENFILENAME.nFilterIndex],1
        m2m     [edi+OPENFILENAME.lpstrFile],[lpTargetPath]
        mov     [edi+OPENFILENAME.nMaxFile],MAX_PATH
        m2m     [edi+OPENFILENAME.lpstrTitle],[lpTitle]
        mov     [edi+OPENFILENAME.Flags],OFN_EXPLORER+OFN_FILEMUSTEXIST+OFN_HIDEREADONLY
        invoke  GetOpenFileName,edi
        ret
  endp

  proc  _opensave uses ebx esi edi, lpWnd,lpTargetPath,lpFilter,lpTitle
        local   ofn:OPENFILENAME

        lea     edi,[ofn]
        mov     ecx,sizeof.OPENFILENAME
        xor     al,al
        rep     stosb

        lea     edi,[ofn]
        mov     [edi+OPENFILENAME.lStructSize],sizeof.OPENFILENAME
        m2m     [edi+OPENFILENAME.hwndOwner],[lpWnd]
        m2m     [edi+OPENFILENAME.hInstance],[hInstance]
        m2m     [edi+OPENFILENAME.lpstrFilter],[lpFilter]
        mov     [edi+OPENFILENAME.nFilterIndex],1
        m2m     [edi+OPENFILENAME.lpstrFile],[lpTargetPath]
        mov     [edi+OPENFILENAME.nMaxFile],MAX_PATH
        m2m     [edi+OPENFILENAME.lpstrTitle],[lpTitle]
        mov     [edi+OPENFILENAME.Flags],OFN_FILEMUSTEXIST+OFN_PATHMUSTEXIST+OFN_LONGNAMES+OFN_EXPLORER+OFN_HIDEREADONLY
        invoke  GetSaveFileName,edi
        ret
  endp
    
Post 04 Apr 2006, 14:49
View user's profile Send private message Reply with quote
AsmER



Joined: 25 Mar 2006
Posts: 64
Location: England
AsmER
Hehe,

I just started looking, if it is possible to do thing like:
Code:
lea       reg, structre
mov     [reg+structure.element_of_the_structure], value    

in FASM (I knowed I can do it in MASM) and you sent answer to me(MASM 1:1 FASM). You can't know how much you helped Exclamation
Right, this post can be treated as closed Very Happy

_________________
;\\ http://theasmer.spaces.live.com \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Post 07 Apr 2006, 10:25
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.