The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: James Ladd on April 23, 2005, 03:36:32 AM

Title: is there a simpler way ?
Post by: James Ladd on April 23, 2005, 03:36:32 AM
I have code that looks like this ...

        assume eax : PSTRUCTURE
        mov edx, [eax].field.some_other_field
        assume eax : nothing
        ; use eax


Instead of doing this every time I need to access the elements of the STRUCTURE pointed to by eax,
if there a simple way ?



Title: Re: is there a simpler way ?
Post by: Petroizki on April 23, 2005, 04:27:01 AM
mov edx, [eax].PSTRUCTURE.field.some_other_field
Title: Re: is there a simpler way ?
Post by: James Ladd on April 23, 2005, 04:51:59 AM
Thanks for the quick response however when I do what you suggest it says
main.asm(55) : error A2166: structure field expected
:(

If it helps, in actually trying to invoke a function through a pointer in a structure.
eg: invoke [eax].func.some_function_pointer
Title: Re: is there a simpler way ?
Post by: thomasantony on April 23, 2005, 08:18:52 AM
Hi,
   I don't think you can use invoke with a pointer. you can use call I suppose. Don't you need a PROTO to use invoke. You load the pointer into eax and do call eax or call the pointer directly.

Thomas :U
Title: Re: is there a simpler way ?
Post by: James Ladd on April 23, 2005, 11:35:57 PM
The field in the structure is a pointer to a function and it is typedef'd.
I could try getting the pointer out of the structure first and then calling it.

Is there a way to apply a prototype to the call ?

eg: invoke [eax].PFN, x, y, z

Here is an example structure / definitions



myfuncx typedef proto dword
pfnmyfunc typedef ptr myfuncx

funcs struct
    myfunc pfnmyfunc
funcs ends

thing struct
    func funcs
thing ends


I hope this helps.

given a pointer to thing I need to invoke the function myfunc.
Title: Re: is there a simpler way ?
Post by: hutch-- on April 24, 2005, 12:10:38 AM
James,

Have a look at a macro in the macros.asm file for MASM32 for a macro called DDPROTO as it may be useful to you. The problem is that INVOKE requires a prototype where you can use CALL without any problems if you don't mind not having the type checking.
Title: Re: is there a simpler way ?
Post by: James Ladd on April 24, 2005, 03:49:54 AM
All is ok now at least as far as compilation is concerned.
I changed

invoke [eax].PMYSTRUCT.func.someFunc, arg1, arg2

to

invoke [eax].MYSTRUCT.func.someFunc, arg1, arg2

and it compiled fine. Which makes sense. Now to see if it actually works.


edit:

Here is an example what I was trying to do. The example works.


; -----------------------------------------------------------------------------
;
.686                                ; create 32 bit code
.model flat, stdcall                ; 32 bit memory model
option casemap :none                ; case sensitive

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\windows.inc
include \masm32\include\masm32.inc
includelib \masm32\lib\masm32.lib

FUNC typedef proto arg1:DWORD, arg2:DWORD
PFUNC typedef ptr FUNC

MYFUNCS struct
    myfunc PFUNC ?
MYFUNCS ends

MYSTRUCT struct
    func MYFUNCS <>
MYSTRUCT ends
PMYSTRUCT typedef ptr MYSTRUCT

.data
    msg db "HERE",13,10,0
    example MYSTRUCT <>
    pexample PMYSTRUCT offset example
.code
start:
    mov [pexample].MYSTRUCT.func.myfunc, foofunc
    invoke [pexample].MYSTRUCT.func.myfunc, 1, 2
    invoke ExitProcess, eax

foofunc proc arg1:DWORD, arg2:DWORD
    invoke StdOut, addr msg
    xor eax, eax
    ret
foofunc endp

end start

Title: Re: is there a simpler way ?
Post by: James Ladd on April 24, 2005, 11:44:13 PM
awwww :(
No comments ?