johnwcurry
Programmer
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"Hello"
;
if (FAILED(SafeArrayPutElement(psa, &x, bstr)))
return false;
}
*ppVal = psa;
return S_OK;
}
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"
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"Hello"
if (FAILED(SafeArrayPutElement(psa, &x, bstr)))
return false;
}
*ppVal = psa;
return S_OK;
}