DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: TYpe mismatch casting to interface

  1. #1
    Guest

    TYpe mismatch casting to interface

    I have an interface defined in a type library. When I implement this
    interface in an ActiveX DLL, I can quite happily carry out the following
    casting to make calls to the interfaces methods:

    Dim theClass As Project1.Class1
    Dim theIface As ITempLib.INewTemporary

    Set theClass = New Project1.Class1
    Set theIface = theClass
    MsgBox theIface.ReturnString

    But if I change the ActiveX DLL to an ActiveX Exe, which I need to do to get
    around some in-process / out-of-process problems, I get a Type mismatch
    error as I try to set theIface.

    Can't see any logic to this, or any existing topics on it in MSDN. Any ideas
    folks?

    Cheers,
    Phil.







  2. #2
    Mark Alexander Bertenshaw Guest

    Re: TYpe mismatch casting to interface

    Phil -

    Are both the interface and the class public? Is the interface defined in a
    type library or a VB project?

    --
    Mark Alexander Bertenshaw
    Programmer/Analyst
    PrimeResponse
    Brentford
    UK
    <PWebb@princetonsoftech.com> wrote in message
    news:399801b1$1@news.devx.com...
    > I have an interface defined in a type library. When I implement this
    > interface in an ActiveX DLL, I can quite happily carry out the following
    > casting to make calls to the interfaces methods:
    >
    > Dim theClass As Project1.Class1
    > Dim theIface As ITempLib.INewTemporary
    >
    > Set theClass = New Project1.Class1
    > Set theIface = theClass
    > MsgBox theIface.ReturnString
    >
    > But if I change the ActiveX DLL to an ActiveX Exe, which I need to do to

    get
    > around some in-process / out-of-process problems, I get a Type mismatch
    > error as I try to set theIface.
    >
    > Can't see any logic to this, or any existing topics on it in MSDN. Any

    ideas
    > folks?
    >
    > Cheers,
    > Phil.
    >
    >
    >
    >
    >
    >




  3. #3
    Guest

    Re: TYpe mismatch casting to interface

    The interface is defined in an external type library (since it is actually
    defined by a C++ component). If we try defining a simple interface as a
    publicnotcreatable class in the vb project for the ActiveX EXE, all is well.
    It's only when we define the interface in an external type library (which we
    have to do).

    So, a class in an ActiveX DLL which implements an interface from a TLB can
    be cast to the interface by a client EXE.
    But, a class in an ActiveX EXE which implements the same interface from a
    TLB cannot be cast to the interface by a client EXE, but leads to a Type
    Mismatch.

    Any more ideas, anyone?

    Cheers,
    Phil.
    Mark Alexander Bertenshaw wrote in message <399845e1@news.devx.com>...
    >Phil -
    >
    >Are both the interface and the class public? Is the interface defined in a
    >type library or a VB project?
    >
    >--
    >Mark Alexander Bertenshaw
    >Programmer/Analyst
    >PrimeResponse
    >Brentford
    >UK
    ><PWebb@princetonsoftech.com> wrote in message
    >news:399801b1$1@news.devx.com...
    >> I have an interface defined in a type library. When I implement this
    >> interface in an ActiveX DLL, I can quite happily carry out the following
    >> casting to make calls to the interfaces methods:
    >>
    >> Dim theClass As Project1.Class1
    >> Dim theIface As ITempLib.INewTemporary
    >>
    >> Set theClass = New Project1.Class1
    >> Set theIface = theClass
    >> MsgBox theIface.ReturnString
    >>
    >> But if I change the ActiveX DLL to an ActiveX Exe, which I need to do to

    >get
    >> around some in-process / out-of-process problems, I get a Type mismatch
    >> error as I try to set theIface.
    >>
    >> Can't see any logic to this, or any existing topics on it in MSDN. Any

    >ideas
    >> folks?
    >>
    >> Cheers,
    >> Phil.
    >>
    >>
    >>
    >>
    >>
    >>

    >
    >




  4. #4
    Anthony Jones Guest

    Re: TYpe mismatch casting to interface

    Phil,

    I'm afraid I haven't got any idea why your having this problem.

    I can tell you that I do a lot this kind of thing without any problem.
    That is define interfaces in IDL to compile to a type lib then implement
    the interfaces in VB classes in both ActiveX.exes and dlls.

    --
    Anthony Jones
    Secta Group Ltd




  5. #5
    Guest

    Re: TYpe mismatch casting to interface

    We found out we were missing dual on the interface - stranbge it worked on
    the ActiveX DLL and not the ActiveX Exe though...

    Anthony Jones wrote in message <399d33f8@news.devx.com>...
    >Phil,
    >
    >I'm afraid I haven't got any idea why your having this problem.
    >
    >I can tell you that I do a lot this kind of thing without any problem.
    >That is define interfaces in IDL to compile to a type lib then implement
    >the interfaces in VB classes in both ActiveX.exes and dlls.
    >
    >--
    >Anthony Jones
    >Secta Group Ltd
    >
    >
    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center