Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DCOM & SAFEARRAY of BSTR's

Status
Not open for further replies.

johnwcurry

Programmer
Dec 3, 2001
1
0
0
US
In my DCOM client/server app, I am attempting to implement a SAFEARRAY of BSTR's in the Server, and pass it back to the client. I have been using "Learning DCOM", by Thuan L. Thai, as well as "COM+ Programming", by Pradeep Tapadiya as guidelines.

I AM able to get the safearray passed back to the client,and the client can savely de-allocate and destroy the passed SAFEARRAY. However the server memory usage coninues to increment each time the client requests the SAFEARRAY from the server.

The Server code is as follows:

IDL def:
[propget, id(9), helpstring("property TestList")] HRESULT TestList([out, retval] SAFEARRAY(BSTR) *pVal);

code:
STDMETHODIMP CAccessRTU::get_TestList(SAFEARRAY **ppVal)
{
// TODO: Add your implementation code here

SAFEARRAY *psa;
SAFEARRAYBOUND sa;
BSTR bstr;
_bstr_t *pbStr;
sa.lLbound = 0;
sa.cElements = 200;
if ((psa = SafeArrayCreate(VT_BSTR, 1, &sa)) == NULL)
return false;
if(psa->cDims != 1)
return false;

for (long x = sa.lLbound; x < (long)sa.cElements; x++)
{
if (FAILED(SafeArrayGetElement(psa, &x, &bstr)))
return false;
bstr = ::SysAllocString(L&quot;Hello&quot;);

if (FAILED(SafeArrayPutElement(psa, &x, bstr)))
return false;
}
*ppVal = psa;
return S_OK;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top