Hello folks!
I'm writing a routine that'll get the last directory opened by the
GetOpenFileName Api.




.data?
TextBuffer db 100 dup (?)

.code
start:
;Code after the GetOpenFileName api routine
cmp eax,TRUE ;Verify if a file was opened
jnz the_end ;If not don't get the last dir

GetsLastDir:
push 40h
push offset Title
push ofn.lpstrFile ;lpstrFile
push 0
call MessageBoxA

;The code above works right it shows a messagebox with
;the path of the last Opened file

mov ecx,sizeof ofn.lpstrFile
lea esi,ofn.lpstrFile
lea edi,TextBuffer
rep movsb

push 40h
push offset Title
push offset TextBuffer
push 0
call MessageBoxA

;But when I try to move ofn.lpstrFile to the TextBuffer variable I get
;a wierd text like: ?O@

The_End:
push 0
call ExitProcess




Could someone please tell me what I did wrong?
Thanks in advance.
Cthulhu
Posted on 2003-06-02 20:02:01 by Cthulhu



GetsLastDir:
push 40h
push offset Title
push ofn.lpstrFile ;lpstrFile
push 0
call MessageBoxA

;The code above works right it shows a messagebox with
;the path of the last Opened file

mov ecx,sizeof ofn.lpstrFile
lea esi,ofn.lpstrFile
lea edi,TextBuffer
rep movsb

When you call MessageBoxA, you correctly treat lpstrFile as the name of a string pointer that is pushed onto the stack.

You must do the same when using REP MOVSB. Instead of LEA, use MOV to copy the pointer into the register:

mov esi,ofn.lpstrFile

SIZEOF is an assembly time operation -- there is no machine code or CPU activity associated with SIZEOF. The size of a pointer field is always 4. Use a function like lstrlen to get the current length of the string.
Posted on 2003-06-02 22:19:57 by tenkey
Thank you very much Tenkey.
Now it works perfectly.:alright:

Best regards
Cthulhu
Posted on 2003-06-03 02:27:31 by Cthulhu