flat assembler
Message board for the users of flat assembler.
Index
> Main > Methods? |
Author |
|
vid 22 Jul 2007, 09:57
first you must understand that 'method' is just an abstraction of something that is in reality (and thus in assembly too) more complex.
In simpler case, method is just a procedure, that takes one extra argument - "this" pointer. As for virtual method (one that can be overloaded), it's more difficult. Every object is just structure in memory. And every object's first member (first thing in structure) is pointer to so-called virtual table (vtab). Virtual table is array of pointers to virtual methods. Every class has it's virtual table, that lists address of corresponding procedure for every it's virtual methods. Virtual table pointer can also act as run-time type information, because it's (obviously) unique for every class. So, method is just a procedure that takes one extra argument - "this" pointer. Now try looking for more info about procedures. Also, i would suggest you not to think about OOP in assembly too much for now, it is quite complicated. First learn classical structural programming, and then head for OOP - this is natural "evolution" of paradigm (whatever university teachers say) |
|||
22 Jul 2007, 09:57 |
|
calpol2004 22 Jul 2007, 10:12
hmm okay, im working with an imported class from a dll (IWebControl to be specific) so i'd presume i'm working with virtual method as the procedure doesn't exist in the list generated by apiresolve. If it isn't then it's just a procedure which needs the pointer of the object as a parameter along with the other parameters, in this case oWb right?
provided its a virtual method i'd need to find the structure of oWb in memory (how would i go about that?) and look in it's first member, the virtual table, in which there is a list of pointers to procedures which i can execute. Well i think i understand it now (thanks vid). I probably should stick to the basic stuff but i really would like to give it a shot before i give up out of confusion . I have done some OOP in the past by working with JAVA, i didn't really get a good grasp of it though. Just need to find some code examples now . I remember finding a webpage with the vtable procedure listings for the class i'm using, was very cryptic and i just dismissed it. I shall dig it up now . Last edited by calpol2004 on 22 Jul 2007, 11:23; edited 1 time in total |
|||
22 Jul 2007, 10:12 |
|
calpol2004 22 Jul 2007, 10:31
okay, i found the link for the page which lists all the procedures for doing something with my web control, here: http://www.autohotkey.com/forum/topic19225.html.
It makes a lot more sense now: for example to refresh the code is this (in C): Code: IE_Refresh(pwb) { DllCall(VTable(pwb, 12), "Uint", pwb) } Now from this i can see that i need to use the function DllCall() or something similar to call a dll at run-time but using the pointer to the procedure instead of the name of the dll or something else that would execute the procedure, and the Vtable() function i'm guessing returns the pointer to the procedure in the Vtab (the 12th in the array). Haven't had any luck finding the functions, i shall probably have to use a different method, any ideas? my code should look something like this if i found it: Code: type db 'Uint',0 ... invoke VTable,object,12 invoke DllCall,eax,type,object i don't know if the Vtable or DllCall functions exists in any Dlls i can use, how else would i go about getting the pointer? |
|||
22 Jul 2007, 10:31 |
|
f0dder 22 Jul 2007, 14:23
That code above is not C code, it is AutoHotKey code. DllCall is a built-in thing from AHK, so is VTable, and the whole weird way of going about stuff.
The standard calling convention for C++ code is thiscall, where the "this" pointer goes into the ECX register... but interfacing with existing C++ code can be complex, you don't necessarily have a vtable if you're not dealing with COM stuff. My advice would be keeping your OOP in C++, doing procedural stuff in assembly, and not trying to mix until you're pretty familiar with both, separately. A little sample code, though, showing why you do this stuff in a HLL instead of assembly... (yeah yeah, you can use fancy macros to make it prettier): Code: mov ecx, [pwb] ; or perhaps lea ecx, [owb] mov eax, [ecx] ; vtable pointer push 3030h ; arg 3 push 42 ; arg 2 push 007 ; arg 1 call dword [eax + 5*4] ; call virtual method 5 |
|||
22 Jul 2007, 14:23 |
|
vid 22 Jul 2007, 15:57
also if it is COM object, then working with it is little different again
|
|||
22 Jul 2007, 15:57 |
|
f0dder 22 Jul 2007, 16:16
vid wrote: also if it is COM object, then working with it is little different again ...especially if you have to work with VARIANT types - then you'd better give up both assembly and C++, and do it in VB :] _________________ - carpe noctem |
|||
22 Jul 2007, 16:16 |
|
vid 22 Jul 2007, 16:20
i didn't even get to VARIANT, what is that? I gave up after i spotted SAFEARRAY
|
|||
22 Jul 2007, 16:20 |
|
calpol2004 22 Jul 2007, 20:14
vid wrote: i didn't even get to VARIANT, what is that? I gave up after i spotted SAFEARRAY Do i use those instead? i've been clueless about what i'm supposed to do for the variant variables. |
|||
22 Jul 2007, 20:14 |
|
f0dder 22 Jul 2007, 20:58
VARIANT are a structure (or well, union) with a bunch of fields etc... not pretty to deal with. Find some .h or .inc file that defines it.
|
|||
22 Jul 2007, 20:58 |
|
calpol2004 22 Jul 2007, 21:40
...Going to be a long night:
Code: typedef struct tagVARIANT { VARTYPE vt; unsigned short wReserved1; unsigned short wReserved2; unsigned short wReserved3; union { unsigned char bVal; short iVal; long lVal; float fltVal;. double dblVal; VARIANT_BOOL boolVal; SCODE scode; CY cyVal; DATE date; BSTR bstrVal; IUnknown FAR* punkVal; IDispatch FAR* pdispVal; SAFEARRAY FAR* parray; unsigned char FAR* pbVal; short FAR* piVal; long FAR* plVal; float FAR* pfltVal; double FAR* pdblVal; VARIANT_BOOL FAR* pboolVal; SCODE FAR* pscode; CY FAR* pcyVal; DATE FAR* pdate; BSTR FAR* pbstrVal; IUnknown FAR* FAR* ppunkVal; IDispatch FAR* FAR* ppdispVal; SAFEARRAY FAR* FAR* pparray; VARIANT FAR* pvarVal; void FAR* byref; }; }; typedef struct FARSTRUCT tagVARIANT VARIANT; typedef struct FARSTRUCT tagVARIANT VARIANTARG; |
|||
22 Jul 2007, 21:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.