Phil Sherrod
2004-07-25 02:51:42 UTC
I need help figuring out how to return a string from a C++ ATL-generated COM
object through an output VARIANT parameter that is not the [out,retval] for the
function. Here is an example function declaration:
ReturnString([out] VARIANT *outString, [out,retval] long *outStatusValue)
Here is a simplified fragment of the code I tried to use:
STDMETHODIMP CDTREG::ReturnString(VARIANT *outString, long *outStatusValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (outString->vt & VT_BYREF) {
*v->vt = VT_BYREF | VT_BSTR;
*v->pbstrVal = _bstr_t("TestOutput");
} else {
v->vt = VT_BYREF | VT_BSTR;
v->bstrVal = _bstr_t("TestOutput");
}
return S_OK;
}
(I believe the VT_BYREF flag is always set, so the Else statements are never
used.)
But the returned string does not show up in the Visual Basic test program that
is calling this method.
I've also tried to manually construct a BSTR using SysAllocString and putting
the 4-byte length header, etc. But that doesn't work either.
Can someone please show me a simple example of how to return a string through a
VARIANT output parameter that is not the [out,retval] parameter for the
function?
object through an output VARIANT parameter that is not the [out,retval] for the
function. Here is an example function declaration:
ReturnString([out] VARIANT *outString, [out,retval] long *outStatusValue)
Here is a simplified fragment of the code I tried to use:
STDMETHODIMP CDTREG::ReturnString(VARIANT *outString, long *outStatusValue)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
if (outString->vt & VT_BYREF) {
*v->vt = VT_BYREF | VT_BSTR;
*v->pbstrVal = _bstr_t("TestOutput");
} else {
v->vt = VT_BYREF | VT_BSTR;
v->bstrVal = _bstr_t("TestOutput");
}
return S_OK;
}
(I believe the VT_BYREF flag is always set, so the Else statements are never
used.)
But the returned string does not show up in the Visual Basic test program that
is calling this method.
I've also tried to manually construct a BSTR using SysAllocString and putting
the 4-byte length header, etc. But that doesn't work either.
Can someone please show me a simple example of how to return a string through a
VARIANT output parameter that is not the [out,retval] parameter for the
function?
--
Phil Sherrod
(phil.sherrod 'at' sandh.com)
http://www.dtreg.com (decision tree modeling)
http://www.nlreg.com (nonlinear regression)
Phil Sherrod
(phil.sherrod 'at' sandh.com)
http://www.dtreg.com (decision tree modeling)
http://www.nlreg.com (nonlinear regression)