Re : Interface pointers over process boundaries 
Author Message
 Re : Interface pointers over process boundaries

I have an outer interface IOuter which requires to return a pointer to
an IInner. IInner exists in a list of IInner * as a global list within
an MTA EXE Service. As an MTA service or EXE application when calling
IInner * pInner = pOuter->Inner () (for instance) a pointer is
returned to the client but when calling an Interface method on pInner
an access violation exception is raised. When built in an InProcess
COM server this works fine. Any ideas how to get around this debacle.

Cheers

Ed



Wed, 19 May 2004 00:33:22 GMT  
 Re : Interface pointers over process boundaries


Fri, 19 Jun 1992 00:00:00 GMT  
 Re : Interface pointers over process boundaries
Perhaps you forgot to AddRef the returned interface pointer?
Of course the code you just provided would never go through
any marshaling channel - it must be something like:

[propget]
HRESULT Inner([out, retval] IInner **ppInner);

Then you call it like:

IInner *pInner = NULL;
hr = pOuter->get_Inner(&pInner);

If you are using #import, it'll look like:

IInnerPtr pInner = pOuter->Inner();

Ah, if that's what you are using, you are not using it correctly - the
generated wrapper returns a class - not an interface pointer! It gets
destroyed before the next line thus freeing the returned interface
pointer and leaving you with a dangling pointer.

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================


Quote:
> I have an outer interface IOuter which requires to return a pointer to
> an IInner. IInner exists in a list of IInner * as a global list within
> an MTA EXE Service. As an MTA service or EXE application when calling
> IInner * pInner = pOuter->Inner () (for instance) a pointer is
> returned to the client but when calling an Interface method on pInner
> an access violation exception is raised. When built in an InProcess
> COM server this works fine. Any ideas how to get around this debacle.

> Cheers

> Ed



Wed, 19 May 2004 07:17:47 GMT  
 Re : Interface pointers over process boundaries
Hi!

I had the similar problem.
You have to create an instance of IInner and return ptr of  QI of it:

class CInner : public CComObjectRootEx<YOUR_THREAD_MODEL>,
    public CComCoClass<CInner, &CLSID_Inner>,
    public IInner
{
private:
    int a;
public:
    CInner() : a(0){}
    HRESULT Clone([in] IInner* p) {if (p) a = p->a; return S_OK;}//if you
need

Quote:
};

//-----------------------------------------
class COuter : public CComObjectRootEx<YOUR_THREAD_MODEL>,
    public CComCoClass<COuter, &CLSID_Outer>,
    public IOuter
{
protected:
    CComPtr<IInner> m_spInner;
public:
    COuter();
    HRESULT GetInner(/*[out]*/ IInner** pp);
Quote:
};

//-----------------------------------------
COuter::COuter()
{
    CComObject<CInner>* p = NULL;
    CComObject<CInner>::CreateInstance(&p);
    if (p)
        p->QueryInterface(IID_IInner, (void**)&m_spInner);
Quote:
}

//-----------------------------------------
HRESULT GetInner(/*[out]*/ IInner** pp)
{
    ATLASSERT(*pp == NULL);

    //the following lines will work good and you will get an interface ptr,
    //but you will get an error when try to call any method,
    //because object is already marshalled on another thread in the another
process
    //you did like this, isn't it?
//    *pp = m_spInner;
//    (*pp)->AddRef();

    //the following lines will help you to solve this problem
    CComObject<CInner>* p = NULL;
    HRESULT hr = CComObject<CInner>::CreateInstance(&p);

    if (SUCCEEDED(hr))
        hr = p->QueryInterface(IID_IInner, (void**)pp);

    if (SUCCEEDED(hr))
        hr = (*pp)->Clone(m_spInner); //    if you need.

    return hr;

Quote:
}

//-----------------------------------------

Hope this help.

Cheers,
    Igor.


Quote:
> I have an outer interface IOuter which requires to return a pointer to
> an IInner. IInner exists in a list of IInner * as a global list within
> an MTA EXE Service. As an MTA service or EXE application when calling
> IInner * pInner = pOuter->Inner () (for instance) a pointer is
> returned to the client but when calling an Interface method on pInner
> an access violation exception is raised. When built in an InProcess
> COM server this works fine. Any ideas how to get around this debacle.

> Cheers

> Ed



Sat, 22 May 2004 01:59:28 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. getting interface pointer from another process..

2. Passing interface pointer across process space

3. IPicture across process boundaries

4. Throwing com exceptions across process boundaries...

5. IXMLDOMNodeList across process boundaries?

6. Connection Point Events Across Processes Boundaries?

7. Can't pass IIDs properly across process boundaries

8. Passing Socket handles across process boundaries??

9. Can't pass IIDs properly across process boundaries

10. pointers & lower boundary

11. aligning a pointer on DWORD boundaries ???

12. How to check the boundary of pointer?

 

 
Powered by phpBB® Forum Software