CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    COM - Query an Interface inherited from IUnknown

    Hey there,

    I've got a bit a strange problem. Which means I think I already know the reason, but I do not see any way around it ^^.

    But let me descripe. Basicly I've got an simple interface inherting from IUnknown:
    Code:
    [
        object,
        ...
    ]
    interface IMyInterface : IUnknown {
    }
    So far so good. Now I want to inherit many other interfaces from this interface so that a method can use different special methods of this interface later on dynamicly in the code:
    Code:
    [
        object,
        ...
    ]
    interface ISpecialInterface1 : IMyInterface {
    }
    
    [
        object,
        ...
    ]
    interface ISpecialInterface2 : IMyInterface {
    }
    
    // ...
    Everything works fine, until I e.g. call QueryInterface of a special class to get an pointer to the base interface:
    Code:
    STDMETHODIMP ISpecialInterface2::GetInterface(/* [out, retval] */ IMyInterface** Interface)
    {
        this->QueryInterface(IID_IMyInterface, reinterpret_cast<void**>(Interface));
        return S_OK;
    }
    Somehow I allways get an AccessViolation Exception or an InvalidCast Exeption. I guess it is because I do not implement IMyInterface so it stays abstract. But usually this is the idea behind an interface. I allways thought the methods are pointers to the real implementations of the methods, but... I don't know ^^.

    Any solutions?

    Thank you,
    - Aschratt.

  2. #2
    Join Date
    Apr 2004
    Location
    England, Europe
    Posts
    2,492

    Re: COM - Query an Interface inherited from IUnknown

    To help you, I think we'll need a bit more detail on what you are doing.

    A question:

    ISpecialInterface2 should only have pure virtual member functions, why is ISpecialInterface2::GetInterface being implemented?
    My hobby projects:
    www.rclsoftware.org.uk

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured