So I am trying to further understand how to take a C++ struct/class and convert that over to a masm style struct. I understand pretty much all the bits and pieces except how to do this when you have functions within the struct. Do I simply define the proto within the struct and then implement in my asm file? Or should I define the proto outside of the struct and use a typedef ptr to the function and use that as a member of the struct?
Example 1
manager_t typedef ptr _manager_t
_manager_t STRUCT
base c_base <>
get_msg proto stdcall self:manager_t
_manager_t ENDS
or would I do something like this?
manager_t typedef ptr _manager_t
get_msg typedef ptr _get_msg
_get_msg proto stdcall self:manager_t
_manager_t STRUCT
base c_base <>
getMsg get_msg ?
_manager_t ENDS
You could distinguish members, methods and functions. For your inspiration, a few snippets from a project I abandoned some months ago ;-)
ClassCounter = 0
CreateClass MACRO TheName:=<close>, TheProc
CurClassName equ <TheName>
ifb <TheProc>
CurClassProc CATSTR <TheName>, <P>
else
CurClassProc equ <TheProc>
endif
MemString CATSTR <TheName>, <_members:# >
CurClassOff = 0
CurClassMethCt = 0
ifidn <TheName>, <close>
ClassCounter = ClassCounter + 1
endif
ENDM
MemCounter=0
AddMembers MACRO Mems:VARARG
LOCAL colon, sl, sr, is
For arg, <Mems>
colon INSTR <arg>, <:>
if colon
sl SUBSTR <arg>, 1, colon-1
sr SUBSTR <arg>, colon+1
is = 0
colon INSTR sr, <WORD>
is = is + colon
colon INSTR sr, <REAL>
is = is + colon
if is
MemString CATSTR MemString, sl, < >, sr, <?# >
else
MemString CATSTR MemString, sl, < >, sr, < !<!># >
endif
else
MemString CATSTR MemString, <arg>, < dd ?# >
endif
ENDM
ENDM
...
.code
CreateClass whatever
AddMembers rc:RECT, myReal8, mydw, my$, myArray$()
AddFunction getrect(hWin) ; returns something
AddMethod setrect rc=left, top, right, bottom ; no retval
AddMethod moverect rc, dx, dy
CreateClass ; no args means <close>
First of all, how the structures exactly build, depends on the compilers, thus you may try to find information specific for your compiler.
Prototypes and typedefs of function pointer can declared anywhere (before their usage). But be warned, there is MASM bug for prototypes: if you use the name of a already declared function (prototype) in any expression that will be expand/evaluate by MASM macro engine, an EXTERN entry will be added to the object file, even if you never use that function.
Also, note that commonly only virtual function will be added as function pointers inside the vTbl - other methods are called by label.