flat assembler
Message board for the users of flat assembler.

Index > Windows > GetOpenFileName wants to delete file :)

Author
Thread Post new topic Reply to topic
at0mic



Joined: 09 Mar 2005
Posts: 12
at0mic
Code:
;just GetOpenFileName -> this prg wants to delete file, I have no idea why... ?

include 'win32ax.inc'
macro   m2m     dest,src
{ 
        push    src 
        pop     dest 
}

.data

  szFilter              db "All Files",0,"*.*",0,0 
  szTitle               db "Select file to delete",0 



  hInstance             dd ? 
  hFileHandle           dd ? 
  hFileSize             dd ? 
  hFileMap              dd ? 
  hFileView             dd ? 

  szFilePath            rb 260
  luna    rb sizeof.OPENFILENAME     ; reservation for structure         OPENFILENAME

.code
proc  _openfile, lpFileBuffer ,.ofs

        lea edi,[.ofs]

        mov     [edi+OPENFILENAME.lStructSize],sizeof.OPENFILENAME 
        mov     [edi+OPENFILENAME.hwndOwner],HWND_DESKTOP 
        m2m     [edi+OPENFILENAME.lpstrFile],[lpFileBuffer] 
        mov     [edi+OPENFILENAME.nMaxFile],MAX_PATH 
        mov     [edi+OPENFILENAME.lpstrFilter],szFilter 
        mov     [edi+OPENFILENAME.nFilterIndex],1 
        mov     [edi+OPENFILENAME.lpstrFileTitle],NULL 
        mov     [edi+OPENFILENAME.nMaxFileTitle],NULL 
        mov     [edi+OPENFILENAME.lpstrInitialDir],NULL 
        mov     [edi+OPENFILENAME.Flags],OFN_EXPLORER+OFN_FILEMUSTEXIST+OFN_HIDEREADONLY 
        mov     [edi+OPENFILENAME.lpstrTitle],szTitle 

        invoke  GetOpenFileName,edi
endp

  start:

        invoke  GetModuleHandle,NULL
        or      eax,eax 
        jz      .exit_prog 

        mov     [hInstance],eax


        stdcall _openfile,szFilePath,luna
        or      eax,eax 
        jz      .exit_prog

.exit_prog:
        invoke  ExitProcess,NULL



.end start
    

i can not figure out what is wrong with it , pls help me.

_________________
at0mic!
Post 24 Jun 2009, 08:33
View user's profile Send private message Reply with quote
pete



Joined: 20 Apr 2009
Posts: 110
pete
Two things:

First, when you use the proc macro to start a procedure, you should not forget to use the ret macro before closing a procedure with the macro endp.

Second, inside your _openfile procedure you should use
Code:
      m2m     edi,[.ofs]
    
instead of assigning via lea!
Post 24 Jun 2009, 12:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

Second, inside your _openfile procedure you should use

Or just "mov edi, [.ofs]". But, I suggest using EAX, ECX, or EDX (or at least saving EDI first), that way you don't destroy a register that is supposed to by non-volatile by the stdcall calling convention. (But remember that after calling GetOpenFileName those three registers will be destroyed after returning but in your code that doesn't matter).
Post 24 Jun 2009, 14:23
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.