flat assembler
Message board for the users of flat assembler.

Index > Main > Methods?

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004 22 Jul 2007, 09:28
I'm currently trying to port something from c++ to asm, and i'm not even sure if it's possible.

How do i port methods like this:

Code:
;oWb being an object pointer
oWb.Navigate(url)
    


into an ASM statement? C++ gets compiled into machine code also, so surely it must be possible? since machine code is just assembly represented differently.
Post 22 Jul 2007, 09:28
View user's profile Send private message MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
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)
Post 22 Jul 2007, 09:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
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 Very Happy (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 Laughing.

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 Confused. 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 Very Happy.


Last edited by calpol2004 on 22 Jul 2007, 11:23; edited 1 time in total
Post 22 Jul 2007, 10:12
View user's profile Send private message MSN Messenger Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
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?
Post 22 Jul 2007, 10:31
View user's profile Send private message MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
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
    
Post 22 Jul 2007, 14:23
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 22 Jul 2007, 15:57
also if it is COM object, then working with it is little different again
Post 22 Jul 2007, 15:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
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 :]

_________________
Image - carpe noctem
Post 22 Jul 2007, 16:16
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 22 Jul 2007, 16:20
i didn't even get to VARIANT, what is that? I gave up after i spotted SAFEARRAY Very Happy
Post 22 Jul 2007, 16:20
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
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 Very Happy


Do i use those instead? i've been clueless about what i'm supposed to do for the variant variables.
Post 22 Jul 2007, 20:14
View user's profile Send private message MSN Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
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.
Post 22 Jul 2007, 20:58
View user's profile Send private message Visit poster's website Reply with quote
calpol2004



Joined: 16 Dec 2004
Posts: 110
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;    
Post 22 Jul 2007, 21:40
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.