I'm doing something wrong here but couldn't find. This is for Tasm. When returning eax=path (as NULL terminated), am doing SetDlgItemTextA but editbox only gets first two chars of it.


Call Browse, hWnd
test eax, eax
jz browsErr
Call SetDlgItemTextA, hWnd, IDC_EDT1, eax

Browse PROC, hwndOwn:DWORD

lea eax, pMalloc
call SHGetMalloc, eax
cmp eax, E_FAIL
jnz init_ole
xor eax, eax

mov eax, hwndOwn
mov BrwInf.bi_hwndOwner, eax
mov BrwInf.bi_pidlRoot, NULL
lea eax, lpszDir
mov BrwInf.bi_pszDisplayName, eax
mov BrwInf.bi_lpszTitle, offset lpszTit
mov BrwInf.bi_lpfn, NULL
mov BrwInf.bi_lParam, 0

lea eax, BrwInf
Call SHBrowseForFolder, eax
mov pidl, eax
cmp pidl, 0
jnz pidl_OK
xor eax, eax

lea eax, lpszDir
call SHGetPathFromIDList, pidl, eax
test eax, eax
jnz idlist_OK
xor eax, eax

mov eax, pMalloc
mov eax, [eax]
call (IMalloc PTR [eax]).Free, pMalloc, pidl

mov eax, pMalloc
mov eax, [eax]
call (IMalloc PTR [eax]).Release, pMalloc

lea eax, lpszDir

lpszTit : db 'Target Folder...',0

Browse ENDP
Posted on 2002-12-16 13:35:53 by cakmak
Hi cakmak,
You need to look at EAX after calling Browse. See if the contents of the address contains what you know should be there. It should be trivially easy to do with a good debugger like http://home.t-online.de/home/Ollydbg/viewer.htm . Keep going back into Browse until you find the problem. If you are not up to speed on a good debugger, you should drop everything and learn how. Ratch
Posted on 2002-12-16 14:42:01 by Ratch
Thanks Ratch,

But, I had been debuged this snippet already and honestly, I do not suppose that the problem in proc completely, because, while debugging have seen that eax=result_path but only SetDlgItemTextA function only copied first two chars. And one more thing, that I tried,

Call Browse, hWnd
Call lstrcpy, offset Dir, eax
Call SetDlgItemTextA, hWnd, IDC_EDT1, eax

and this is works. But, why needs?

Posted on 2002-12-16 18:27:05 by cakmak
I found the problem with your proc. lpszDir is a local var, thus when you leave the proc, the stack will be changed. Therefore, never use lpszDir to store the data, store it in a global var.
Posted on 2002-12-16 21:55:57 by roticv
or better yet, make your procedure have a parameter that lets you pass an address to the destination string...
Posted on 2002-12-17 02:18:57 by JCP
Thanks roticv,

I thought exactly what you said. But when I debugged with Ollydebug saw that the return value is exactly what I expect and SetDlgItemTextA function got this as a parameter flawless, so...I couldn't understand exactly.

and Thanks Readiosys,

Honestly, I have been did the proc exactly what you were suggested and had no problem. Only wanted to do a more modular procedure, so tried to do same changes. My effort is not for only working, and a bit modularity.

...so are you think that this is so far? And what do you think about my "lstrcpy" solution? Is this related to my system? Since lstrcpy could get the same return value. I'm a bit confused. :confused:

Posted on 2002-12-17 12:11:35 by cakmak
Yes, EAX will have the value you want. But the call to SetDlgItemTextA will overwrite the Browse locals with its own local variables.
After Browse:

[ESP+ 0] ...
[ESP- 4] hWnd from Browse
[ESP- 8] Return address from Browse
[ESP-12] Old EBP from Browse
[ESP-16] plid from Browse
[ESP-20] pMalloc from Browse
[ESP-??] BrwInf from Browse
[ESP-??] lpszDir from Browse

On entry to SetDlgItemTextA:

[ESP+12] address of text, overwrites hWnd from Browse
[ESP+ 8] control ID, overwrites Return address from Browse
[ESP+ 4] hWnd, overwrites Old EBP from Browse
[ESP+ 0] Return address, overwrites plid from Browse
Notice how, starting with plid, your locals from Browse are being overwritten by the call to SetDlgItemTextA. SetDlgItemTextA will call other subroutines to write the text out, including a call to SendMessageA. Then your window proc will, if it doesn't handle WM_SETTEXT, call DefWindowProcA. That API will call another routine. Text will not be drawn until a BitBlit has been called.

Each level of call eats away at the local data in Browse. So, by the time Windows is able to draw the text on the screen, a lot of that data will have been corrupted.
Posted on 2002-12-17 15:42:02 by tenkey
Thanks tenkey,

Now I learned. Good explanation. I couldn't thought this.

Thanks to all whose share experience with others.

Posted on 2002-12-17 18:14:04 by cakmak
hi over there!

what is LPMALLOC a kind of type?
Posted on 2004-01-18 08:44:43 by Bubu-Boy
a dword if i am not wrong..
Posted on 2004-01-18 08:46:11 by roticv