Home > Software engineering >  Developed a com component, use c to collapse to the _Free call release
Developed a com component, use c to collapse to the _Free call release

Time:10-03

The inline void _bstr_t: : Data_t: : _Free () throw ()
{
If (m_wstr!=NULL) {
: : SysFreeString (m_wstr);
}

If (m_str!=NULL) {
The delete [] m_str;
}
}


The inline _variant_t: : ~ _variant_t () throw ()
{
: : VariantClear (this);
}

There is also a here also often collapse


The great spirit show reason, thank you!

CodePudding user response:

How to use the BSTR and variant of your code?

CodePudding user response:

After the delete and free remember to assign a NULL, avoid wild pointer,

CodePudding user response:

The
reference 1/f, HDT response:
how to use the BSTR and variant of your code?


Object is as follows:
STDMETHODIMP Ctarget: : put_group (IDispatch * newVal)
{
//TODO: add in this implementation code
IMPLEMENT_IDISPATCHPTR_COMOBJ_PUTMOTHOD2 (group);
//return S_OK.
}


STDMETHODIMP Ctarget: : get_groups (VARIANT * pVal)
{
//TODO: add in this implementation code
IMPLEMENT_VARIANT_T_COMOBJ_GETMOTHOD (groups);
//return S_OK.
}


STDMETHODIMP Ctarget: : put_groups (VARIANT newVal)
{
//TODO: add in this implementation code
IMPLEMENT_VARIANT_T_COMOBJ_PUTMOTHOD (groups);
//return S_OK.
}


STDMETHODIMP Ctarget: : get_subscribers (VARIANT * pVal)
{
//TODO: add in this implementation code
IMPLEMENT_VARIANT_T_COMOBJ_GETMOTHOD (subscribers);
//return S_OK.
}


STDMETHODIMP Ctarget: : put_subscribers (VARIANT newVal)
{
//TODO: add in this implementation code
IMPLEMENT_VARIANT_T_COMOBJ_PUTMOTHOD (subscribers);
//return S_OK.
}





Invoked as follows:
Void put_group (LPDISPATCH newValue)
{
The static BYTE parms []=VTS_DISPATCH;
InvokeHelper (0 x4, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, newValue);
}
The VARIANT get_groups ()
{
The VARIANT result;
InvokeHelper (0 x5, DISPATCH_PROPERTYGET VT_VARIANT, (void *) & amp; The result, NULL);
return result;
}
Void put_groups (VARIANT& NewValue)
{
The static BYTE parms []=VTS_VARIANT;
InvokeHelper (0 x5, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, & amp; NewValue);
}
The VARIANT get_subscribers ()
{
The VARIANT result;
InvokeHelper (0 x6, DISPATCH_PROPERTYGET VT_VARIANT, (void *) & amp; The result, NULL);
return result;
}
Void put_subscribers (VARIANT& NewValue)
{
The static BYTE parms []=VTS_VARIANT;
InvokeHelper (0 x6, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms, & amp; NewValue);
}

CodePudding user response:

Look at the first result is initialized,

CodePudding user response:

So, for example, is as follows:
The VARIANT get_groups ()
{
The VARIANT result;
InvokeHelper (0 x5, DISPATCH_PROPERTYGET VT_VARIANT, (void *) & amp; The result, NULL);
return result;
}

Return to try using the following way:
Return CComVariant (result). Copy ();
Or
TRUE, return _variant_t (result) GetVARIANT ();

good luck!
  • Related