CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Aug 2002
    Location
    Madrid
    Posts
    4,588

    COM - Can a simple C++ class be used as a COM object ?

    I have some doubts...

    I have coded a C++ class that includes methods
    Code:
    HRESULT STDMETHODCALLTYPE QueryInterface(
        /* [in] */ REFIID riid, 
        /* [iid_is][out] */ void __RPC_FAR *__RPC_FAR *ppvObject);
    ULONG STDMETHODCALLTYPE AddRef(void);
    ULONG STDMETHODCALLTYPE Release(void);
    Where AddRef and Release don't do anything and QueryInterface fails on every attempt. (meaning it sets *ppvObject to NULL and returns S_FALSE).

    The rest of the class is comprised of the implementation of another COM interface namely ITextHost. Now I'm creating a COM object that takes an ITextHost interface as a parameter. Is it OK to pass it static_cast<ITextHost*>(this) ?

    My C++ class does not need to be a creatable COM object. It only needs to be called through COM once it has been created. It is not supposed to be derived from IDispatch, but only from IUnknown (hence QueryInterface, AddRef and Release)

    My guess is that I should at least allow QueryInterface to succeed for IUnknown and ITextHost.

    BUT, provided this, is this really supposed to work ? It does work in my example code (on my machine), but it seems a bit dodgy.
    Attached Files Attached Files

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