Announcement

Collapse
No announcement yet.

passing interfaces - no type checking?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • José Roca
    replied
    PowerBASIC doesn't seem to do much in the way of type checking on interface parameters.
    Which is useful in some cases, such when it references an interface that you have to implement later.

    Leave a comment:


  • Fred Harris
    replied
    I was wrong

    No, I was wrong on that Chris, and its good you questioned it. I should have corrected that statement; right after your post I checked it and found the same thing you did; PowerBASIC doesn't seem to do much in the way of type checking on interface parameters.

    Give me a second and I'll post the little piece of code I tried, and show some bizarre results.

    Leave a comment:


  • Chris Holbrook
    replied
    Fred, I don't quite follow. Do you mean that even if the "wrong" interface pointer is supplied, the specified method will be retrieved if it exists?

    Leave a comment:


  • Fred Harris
    replied
    If a class supports multiple interfaces, it has the capacity to hand out these interfaces in the form of virtual function table pointers to interested clients. Lets say a class contains an ix, iy, and iz interface, and you obtain an ix interface from the class in the usual manner. In either Visual Basic or PowerBASIC you'll get any of the other interfaces by doing something as simple as this...

    iy = ix

    What happens (under water) is that VB or PB performs a QueryInterface() call where one of the parameters of the call is the requested interface. If that interface is implemented within the class you'll get a valid interface pointer from the call that you can use.

    Also, in PowerBASIC anyway, you can pass any interface to a routine because all interfaces ultimately have IUnknown as their 1st methods; i.e., all interfaces are polymorphs of IUnknown.

    It seems you may have also stumbled onto the fact that passing an interface pointer causes a QueryInterface call if the interface passed is different from the type specified in the call.

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Edwin Knoppert View Post
    Imo it is invoking the desired interface under water.
    If objptr differs from in and use i am right.
    Edwin if only I understood what you are saying!

    Leave a comment:


  • Edwin Knoppert
    replied
    Imo it is invoking the desired interface under water.
    If objptr differs from in and use i am right.
    If the same.. we have a problem

    Check out my items question.
    property items As Interface2
    property = Me
    End property

    PB invokes (queryinterface) the desired interface from the class.
    Excellent stuff!!

    Leave a comment:


  • Chris Holbrook
    replied
    So wouldn't represent better management of our expectations to pass all interfaces as type Interface ? - or would this not be right for COM?

    Leave a comment:


  • Chris Holbrook
    replied
    Originally posted by Fred Harris View Post
    The 'jump table' is the vtable Chris.
    Oh, I see. Gosh you have been busy over there haven't you?

    Leave a comment:


  • Fred Harris
    replied
    jump table

    The 'jump table' is the vtable Chris. Maybe this will help...

    Leave a comment:


  • Michael Mattias
    replied
    Passed UDT parameters aren't checked, either.. except for the SIZEOF(same). May be related.

    Leave a comment:


  • Chris Holbrook
    started a topic passing interfaces - no type checking?

    passing interfaces - no type checking?

    Blundering through a bit of coding this morning I noticed that if a parameter is passed AS <interfacename>, then the wrong interface can be supplied without any problems arising until the wrong interface method is called. My guess is that methods are accessed via a jump table rather than being called at explicit addresses like SUBs and FUNCTIONS. So all the "AS myinterface" does it to tell which jump table to use, and this "typing" is not enforced. I've only tried interfaces in the same CLASS so far. Can anyone confirm thsi?
Working...
X