Hi there !! I was asking myself if there is any way in masm to access a local variable of a parent procedure ... I mean ...

WndProc proc hWnd:HWND, uMsg:UINT, ....
invoke RunMacro, wParam
WndProc endp

When I'm inside the RunMacro proc, is there any way to access the hWnd variable of the WndProc without passing it as a parameter or without reading directly in the Stack ? I mean, obviously I'll have to read the stack, but maybe Masm has a way to make reference to it without having to deal with the stack all the time.
Thanx a lot in advance...:tongue:


-MagicMac.
Posted on 2001-09-26 21:48:49 by magicmac
No. It's that way by design. (Could create a macro maybe? :))
Posted on 2001-09-26 21:56:13 by bitRAKE
you can get the old frame pointer, which is normally located at . with this pointer, you can access all local variables and parameters of the calling proc.

in your example to get hwnd code:

mov eax,
mov eax,

japheth
Posted on 2001-09-27 03:45:07 by japheth
Thanx a lot japheth, I'll try that one...
Posted on 2001-09-27 21:01:34 by magicmac
Hmmmm... I'd be careful with this stuff... you could easily get into spegetti code. Im not doubting there may be a use, but im pretty sure its cause is a rare one.

NaN
Posted on 2001-09-27 22:11:56 by NaN
Nan, the example above (My original post) was trivial, the real problem is that I'm creating threads in my app, and I need to pass around a pair of values, the CreateThread can pass only one parameter and I need to check much more than one.
The solution was a mixture of what japheth told me and yeah, a little bit of spaghetti, but anyway, it's just one place where I need to do that, and It works ... :)
Thanx a lot anyway :alright:

BTW, BitRake, I'm sure you can do a Macro, but I won't defeat you at all ... Heheh :) I saw your Switch Case Macro and it's great !! ...


-MagicMac.
Posted on 2001-09-27 23:17:52 by magicmac
Sorry, but this is definitely not the best way (in my opinion).

A Better solution

    [*] Create a stucture for all the stuff needed to pass.
    [*] Before thread is created, allocate Heap (or LOCAL :) ) memory, the size of this structure.
    [*] Fill the alocated memory using the structure as a template, and the memory address.
    [*] Create the thread
    [*] Pass the ADDRESS of the allocated memory
    [*] The thread then does what it needs with the info, getting data out with the structure template.


    I could code an example, but i dont think you need this.

    NaN
Posted on 2001-09-27 23:31:12 by NaN
magicmac: Like NaN said, it's not recommended to do it this way. You can do it because you can do anything in asm, but that doesn't mean it's wise to do it. The structure method is much safer and also the standard way to do such a thing.

Thomas
Posted on 2001-09-28 03:49:34 by Thomas
I know that you can only pass one DWORD address to a new thread so the structure is a good idea but I dont see the problem of passing whatever parent value you need through the structure.

You could use a global value and this would work but the thread would be dependent on it which reduces the portability of the thread if you wanted to use it in other code as a reusable procedure.

regards,

hutch@pbq.com.au
Posted on 2001-09-28 05:10:44 by hutch--
Nan: I don't know why I didn't even think of a Structure. Butta Mai, yeah, I know why... Just because my little experience... I'll do a Struct, it's much better...

Thomas: I knew that wasn't a "wise" method, the problem was that I didn't have any other idea on how to do it. By the way, I have the Window Assembly Language and Systems Programming -Barry Kauler- that says that every nested proc can access the local variables of the outter procs, the only thing he forgot is the explain how... So I did it that way. :)

Hutch: In this case, I can't use a Global because I know the Thread will be called -sometimes- simultaneously, and each time it's called it will receive a different value, so that's why I must use a local.


Thanks a lot for all of you.


-MagicMac.
Posted on 2001-09-28 08:07:54 by magicmac