• Welcome to Valhalla Legends Archive.
 

AddressOf

Started by The-FooL, July 27, 2004, 09:37 PM

Previous topic - Next topic

The-FooL

I am creating a queue class, with methods for adding items to a queue, etc.  This is for a battle.net bot, so I need to have a timer within the class module to fire for when to send the next message.  The problem is that this class is not always associated with a form(It is just a botclass loaded into memory, with a queclass).  So, I cant use a timer control on every form.  

I was all set to use the SetTimer and KillTimer API to create a unique timer for every instance of the class, until I discovered that the AddressOf used to set the callback functions only applies to procedures placed within normal modules(I cant callback a routine within the class).

Creating a public module routine to handle all the timers wont work directly, because multiple instances of the bots/ques will be loaded at once.

Is there some way to avoid this problem, a workaround, or a way to create an individual timer for each class?  If all else fails, I'll just find a crappy way to implement the queues.

Stealth

I tried to do this once, with a timer class I wrote. The closest I came theoretically was to assign IDs to each timer then pass the IDs to the timer procedure in the extra argument (one of them was available to fill with user-defined data). That way you could translate the ID into the instance the response would go to and indeed you could do it with just one procedure. (Note that this was a long time ago, and I might be completely wrong.)

I also watched TheMinistered try to grab the procedure address of a method inside a class. I don't remember what that applied to but it would appear that it's possible, but very difficult. Someone else will have to help you on that. :)

HTH
- Stealth
Author of StealthBot

Adron

The procedure address of a method within a class could be grabbed, but you won't be able to have Windows call it correctly for you.

It's a function like any other, but in addition to the arguments *you* list for it, it must also be passed the address of the instance of the class that it's supposed to work with. It won't match the function declaration Windows wants for the TimerProc function.

TheMinistered

#3
Yes, I found this out quickly.  The hidden this / me pointer and return value address screw it all up.  I guess you could in theory still do it, but you wouldn't be able to use the Me object, i'll check back later.

The-FooL

I have generally done what stealth said, but I don't know what extra argument he was talking about.  What I did do, is store the integer identifying the timer(returned by the SetTimer function) into the que class.  When the public TimerProc sub was called, I looped through an array of the que classes to find the one with the correct identifying integer, then called the function on that instance.  A little roundabout, but it seems to work.  Still need more extensive testing.  Thanks guys.