Valhalla Legends Forums Archive | Visual Basic Programming | VB6 - Calling an AddressOf?

AuthorMessageTime
JoeTheOdd
For a project I'm making, there's a glue class between some plugin DLL's and the main program itself. The glue class will have an Initialize function where several things, primarily a reference to the socket in use, and the AddressOf to the AddChat procedure, will be passed.

From there, though, I'd like to include an AddChat procedure in that class which will call the AddressOf that was passed to it in Initialize, thus calling the real AddChat.

Does anyone know how to do this?
December 3, 2006, 7:38 AM
HeRo
[quote author=topaz link=topic=16100.msg162107#msg162107 date=1165132687]
yes
[/quote]
I love you.
December 3, 2006, 8:07 AM
warz
Well, in C++ you can just pass the address of the addchat function, and in your class create a function pointer, given the original address. I see youre using Visual Basic. I don't know how functions pointers work, or if theyre even possible in Visual Basic. Just after a quick google search though, the following link looks like it talks about visual basic function pointers. You might wanna check it out, or google on your own for that term.

http://www.15seconds.com/issue/021002.htm
December 3, 2006, 8:25 AM
JoeTheOdd
[quote author=heRo link=topic=16100.msg162108#msg162108 date=1165133258]
[quote author=topaz link=topic=16100.msg162107#msg162107 date=1165132687]
yes
[/quote]
I love you.
[/quote]

I don't.

[quote author=warz link=topic=16100.msg162110#msg162110 date=1165134315]
Well, in C++ you can just pass the address of the addchat function, and in your class create a function pointer, given the original address. I see youre using Visual Basic. I don't know how functions pointers work, or if theyre even possible in Visual Basic. Just after a quick google search though, the following link looks like it talks about visual basic function pointers. You might wanna check it out, or google on your own for that term.

http://www.15seconds.com/issue/021002.htm
[/quote]

Thanks.
December 3, 2006, 8:48 AM
TheMinistered
The short answer would be to rewrite your classes vtable.  The vtable is like a table that contains pointers to all the functions in your class.  It is used at runtime to lookup a procedures address, move it into a register, then call.  Basically, change the adress of the AddChat procedure in the vtable to the AddChat address.  Doing this cross-application might not work.

At any rate, there is an example of how to do this on the VB6 Extrawork Marshaller I released on this forum.  It uses asm via vtable rewriting... the asm emulates the fastcall.


At any rate, I don't suggest doing things this way if its cross-application (i.e. executable and dlls).  You should think about passing object references and such (ObjPtr fxn).
December 13, 2006, 3:08 AM
A2
could you use CallWndProc or vb's CallByName as alternatives?
February 13, 2007, 2:47 AM

Search