• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

How do you COM experts do this sort of thing?

Started by Chris Holbrook, December 27, 2012, 04:41:36 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Chris Holbrook

I have developed a useful little PB Listbox class which manages a n-column Listbox containing only text. To obtain data in response to the wm_drawitem message, one of the class's methods calls a user-written function using an address supplied via a property, and receives a data string result. This works satisfactorily.

However, when this class is instantiated inside another class, the calling convention for a non-class proc is not appropriate for calling a method in the "owner class", which is where the data source belongs.

How should I pass the address of the appropriate method of the "owner" interface to the Listbox object? Don't want to pass the interface, because then the Listbox class code would have to be changed whenever it is called from a new class.

Thanks of thinking for me!



José Roca

#1
We don't do this sort of thing. Only those trying to do OOP with COM try to do it :)

DIM pthis AS DWORD PTR
pthis = OBJPTR (<interface>)

and then pass @@pthis[<offset of the method in the virtual table>]

Then to call it, you will have to declare a function prototype and use CALL DWORD.

I don't understand what problem do you have passing the interface reference instead. You will need to pass it anyway, with OBJPTR(<interface>), since it is the first parameter that you need to pass in the CALL DWORD call.


Chris Holbrook

Thank you for your reply Jose. My instinct is to imitate you by avoiding the method which you describe.

I'm hoping to avoid source code changes to the Listbox class when it  it called from different classes, so I don't want the owning object class name in there.

I can do it by using a global collection class to contain the data, constructing a key to localise the data to the instance of the Listbox object.