Jose's Read Only Forum 2023

General Category => General Discussion => Topic started by: Chris Holbrook on December 27, 2012, 04:41:36 PM

Title: How do you COM experts do this sort of thing?
Post by: Chris Holbrook on December 27, 2012, 04:41:36 PM
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!


Title: Re: How do you COM experts do this sort of thing?
Post by: José Roca on December 27, 2012, 07:28:30 PM
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.

Title: Re: How do you COM experts do this sort of thing?
Post by: Chris Holbrook on December 27, 2012, 08:34:45 PM
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.