News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

is there a simpler way ?

Started by James Ladd, April 23, 2005, 03:36:32 AM

Previous topic - Next topic

James Ladd

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 ?




Petroizki

mov edx, [eax].PSTRUCTURE.field.some_other_field

James Ladd

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

thomasantony

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
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

James Ladd

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.

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

James Ladd

#6
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


James Ladd