Add Method in COM Problem. please help? 
Author Message
 Add Method in COM Problem. please help?

I want to add a Method  that  passADO Recordset. Which data type of the  paramemter should be used?
I try to use VARIENT as the data type tp pass it but in the Get Method such as GetRecordset(VARIANT *var)
How to write the method so that the recordset can pass out by the GetRecordset(VARIANT *var)?
Or I use the wrong data type?

--

Regards,
Analyst Programmer,
Anthony Lam
Jade Flex Ltd



Sat, 05 Jun 2004 13:08:32 GMT  
 Add Method in COM Problem. please help?
You can use either the _variant_t or COleVariant class to make things easier.
Remember, if the function calls for a VARIANT *, pass the address of your
variant (using &), not the variant itself.


Sat, 05 Jun 2004 13:40:41 GMT  
 Add Method in COM Problem. please help?
I also don't know much. Would you mind to show me how to do that? Really
thanks you!
In the COM class, it contain a member variable _RecordsetPtr pRs and pRs
have been created and have Opened.
Then How to use GetRecordset(VARIANT* pVar) to get the pRs??

GetRecordset(VARIANT* pVar)
{
       pVar->vt = VT_UNKNOWN;
       pVar->punkVal =(IUnknown*) pRs;
       return S_OK;

Quote:
}

But after I call this method, as the folloing:
...//create the instance of the COM object
_variant_t   var_rs;
p->GetRecordset(var_rs);*//Let p is the smart point of the COM object
_RecordsetPtr ptr = (_RecordsetPtr)var_rs.punkVal;

But the ptr is invalid, what's wrong? Can you show me how to do that?



Quote:
> You can use either the _variant_t or COleVariant class to make things
easier.
> Remember, if the function calls for a VARIANT *, pass the address of your
> variant (using &), not the variant itself.



Sat, 05 Jun 2004 15:49:51 GMT  
 Add Method in COM Problem. please help?
See inline ...

Quote:

> I also don't know much. Would you mind to show me how to do that? Really
> thanks you!
> In the COM class, it contain a member variable _RecordsetPtr pRs and pRs
> have been created and have Opened.
> Then How to use GetRecordset(VARIANT* pVar) to get the pRs??

> GetRecordset(VARIANT* pVar)
> {
>        pVar->vt = VT_UNKNOWN;
>        pVar->punkVal =(IUnknown*) pRs;
>        return S_OK;
> }

It can be like this:

STDMETHODIMP CYourObjectImpl::GetRecordset(/*[out, retval]*/ VARIANT* pVar)
{
    IUnknown* pUnk = NULL;
    HRESULT hr = pRs.QueryInterface(IID_IUnknown, &pUnk); // internally
calls AddRef()
    if ( FAILED(hr) )
        return hr;

    CComVariant v = pUnk;
    return v.Detach(pVar);

Quote:
}

BTW remember - you should always increment reference counter on interface
pointer you're returning
with AddRef() or QueryInterface().

Quote:
> But after I call this method, as the folloing:
> ...//create the instance of the COM object
> _variant_t   var_rs;
> p->GetRecordset(var_rs);*//Let p is the smart point of the COM object
> _RecordsetPtr ptr = (_RecordsetPtr)var_rs.punkVal;

> But the ptr is invalid, what's wrong? Can you show me how to do that?

You can simply do this that way (if p is smart pointer of course):

try
{
    // ...
    _RecordsetPtr ptr = p->GetRecordset();

Quote:
}

catch ( _com_error& e )
{
    // handle errors here ...

Quote:
}

---
Daniel Bary3a


Sat, 05 Jun 2004 18:59:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Add Method in COM Problem. please help?

2. My Problems With IndexOf Method - Please Help

3. error C2039: after adding method to COM interface

4. Error while adding method to COM interface.

5. Please Help with Adding to Registry Problem

6. Please Help with Adding to Registry Problem

7. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

8. Simple COM Problem. Please help a dummy

9. Please help!!!!Please help!!!!Please help!!!!

10. problem in adding new method

11. Add methods to an existing object (IDL problem)

12. Problems with VC++ 5.0, adding methods to interface dialog

 

 
Powered by phpBB® Forum Software