Passing a Pointer to Pointer to an Interface 
Author Message
 Passing a Pointer to Pointer to an Interface

Hi,
I have the following defenitions of the two interfaces to be used by a VB
client ,I have two questions,

a)should I create the ITest interface using CoCreateInstance or can I use
CComPtr?
b)should I do an AddRef on the newly created ITest interface * when passing
the interface?

interface ITestCreator : IDispatch
 {
  [id(1), helpstring("method callme")]HRESULT callme([out,retval] ITest **
testObject);
 };
 interface ITest : IDispatch
 {
  [propget, id(1), helpstring("property testid")] HRESULT testid([out,
retval] long *pVal);
  [propput, id(1), helpstring("property testid")] HRESULT testid([in] long
newVal);
  };

say in the implementation of
STDMETHODIMP CTestCreator::callme(ITest ** test)
{
//implementaion

Quote:
}



Sat, 10 Jul 2004 20:27:55 GMT  
 Passing a Pointer to Pointer to an Interface
See inline
-------------
Daniel Bary3a


Quote:
> Hi,
> I have the following defenitions of the two interfaces to be used by a VB
> client ,I have two questions,

> a)should I create the ITest interface using CoCreateInstance or can I use
> CComPtr?
> b)should I do an AddRef on the newly created ITest interface * when
passing
> the interface?

> interface ITestCreator : IDispatch
>  {
>   [id(1), helpstring("method callme")]HRESULT callme([out,retval] ITest **
> testObject);
>  };
>  interface ITest : IDispatch
>  {
>   [propget, id(1), helpstring("property testid")] HRESULT testid([out,
> retval] long *pVal);
>   [propput, id(1), helpstring("property testid")] HRESULT testid([in] long
> newVal);
>   };

> say in the implementation of
> STDMETHODIMP CTestCreator::callme(ITest ** test)
> {

         // You can use raw pointer ...
        ::CoCreateInstance(CLSID_Test, NULL, CLSCTX_ALL, IID_ITest, (void
**)test);
        // and call interface methods if you'd like ...
        // i.e. test->someInterfaceMethod(...)

        // ... or CComPtr<> ...
        CComPtr<ITest> ptrTest;
        ptrTest.CoCreateInstance(CLSID_Test);
        // and call interface methods if you'd like ...
        // i.e. test->someInterfaceMethod(...);
        *test = ptrTest.Detach();

        // ... or CComObject<> ...
        CComObject<CTest>* pTest = NULL;
        CComObject<CTest>::CreateInstance(&pTest);
        pTest->AddRef();
        // ... and call methods or set members of a class which implements
ITest interface
        // i.e. pTest->m_someIntMember = 5, pTest->someMethod(...)
        pTest->QueryIterface(IID_ITest, (void **)test);
        pTest->Release();

        // I prefer he last one method - of course if
        // ITest and ITestCreated are located in the same library -
        // if not use first or second approach

- Show quoted text -

Quote:
> }



Sat, 10 Jul 2004 20:55:42 GMT  
 Passing a Pointer to Pointer to an Interface
Works perfectly fine,
Thanks
Shyam

Quote:
> See inline
> -------------
> Daniel Bary3a



> > Hi,
> > I have the following defenitions of the two interfaces to be used by a
VB
> > client ,I have two questions,

> > a)should I create the ITest interface using CoCreateInstance or can I
use
> > CComPtr?
> > b)should I do an AddRef on the newly created ITest interface * when
> passing
> > the interface?

> > interface ITestCreator : IDispatch
> >  {
> >   [id(1), helpstring("method callme")]HRESULT callme([out,retval] ITest
**
> > testObject);
> >  };
> >  interface ITest : IDispatch
> >  {
> >   [propget, id(1), helpstring("property testid")] HRESULT testid([out,
> > retval] long *pVal);
> >   [propput, id(1), helpstring("property testid")] HRESULT testid([in]
long
> > newVal);
> >   };

> > say in the implementation of
> > STDMETHODIMP CTestCreator::callme(ITest ** test)
> > {
>          // You can use raw pointer ...
>         ::CoCreateInstance(CLSID_Test, NULL, CLSCTX_ALL, IID_ITest, (void
> **)test);
>         // and call interface methods if you'd like ...
>         // i.e. test->someInterfaceMethod(...)

>         // ... or CComPtr<> ...
>         CComPtr<ITest> ptrTest;
>         ptrTest.CoCreateInstance(CLSID_Test);
>         // and call interface methods if you'd like ...
>         // i.e. test->someInterfaceMethod(...);
>         *test = ptrTest.Detach();

>         // ... or CComObject<> ...
>         CComObject<CTest>* pTest = NULL;
>         CComObject<CTest>::CreateInstance(&pTest);
>         pTest->AddRef();
>         // ... and call methods or set members of a class which implements
> ITest interface
>         // i.e. pTest->m_someIntMember = 5, pTest->someMethod(...)
>         pTest->QueryIterface(IID_ITest, (void **)test);
>         pTest->Release();

>         // I prefer he last one method - of course if
>         // ITest and ITestCreated are located in the same library -
>         // if not use first or second approach
> > }



Sun, 11 Jul 2004 12:26:04 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Passing interface pointer

2. Passing interface pointer from VC++ to VB

3. COM/ATL novice:passing object pointers through methods on a COM interface

4. proper way for passing com interface pointers

5. Can I pass the pointer of interface between the two threads

6. run time error when passing a pointer to struct for a dual interface

7. Passing interface pointer through event

8. Passing interface pointers over internet

9. Help with passing interface pointers

10. passing interfaces pointers?

11. Passing Interface pointer from local server to MFC app

12. Anyone know how to return / pass Interface Pointers

 

 
Powered by phpBB® Forum Software