Deprecated: Array and string offset access syntax with curly braces is deprecated in /homepages/21/d38531796/htdocs/jose/smfforum/Sources/Subs.php on line 3825
How do you COM experts do this sort of thing?

Author Topic: How do you COM experts do this sort of thing?  (Read 2461 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris Holbrook

  • Newbie
  • *
  • Posts: 44
  • User-Rate: +5/-2
How do you COM experts do this sort of thing?
« 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!



Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2487
  • User-Rate: +204/-0
Re: How do you COM experts do this sort of thing?
« Reply #1 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.

« Last Edit: December 27, 2012, 07:34:22 PM by José Roca »

Offline Chris Holbrook

  • Newbie
  • *
  • Posts: 44
  • User-Rate: +5/-2
Re: How do you COM experts do this sort of thing?
« Reply #2 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.