passing Safearray to VB
From: haglu (tfa613_at_yahoo.de)
Date: 09/04/04
- Next message: Patty O'Dors: "Re: custom licensing scheme"
- Previous message: Kyle Alons: "Re: COM API for existing C++ library"
- Next in thread: haglu: "Re: passing Safearray to VB"
- Reply: haglu: "Re: passing Safearray to VB"
- Messages sorted by: [ date ] [ thread ]
Date: 4 Sep 2004 08:04:10 -0700
Hello,
I try to pass an array of BSTR to a VB client. When the VB procedure
exits, I get a Firstchance Exception in the Server. I think there is
anything wrong with the memory allocation (Windbg output: ...
ole32!CoTaskMemFree ...). ???? But I cant find the mistake.
Can anybody help?
idl:
HRESULT GetComponentNames([in]BSTR bstrFileName, [out,retval] VARIANT*
pNamesArray);
------------------------------------------------------
CPP Server:
HRESULT CExperiment::GetComponentNames(BSTR bstrFileName, VARIANT*
pNamesArray)
{
SAFEARRAYBOUND rgaBound[1];
rgaBound[0].lLbound=0;
rgaBound[0].cElements = m_ComponentNames.size();
ReadFile(bstrFileName); // read m_ComponentNames
VariantInit(pNamesArray);
pNamesArray->vt = VT_ARRAY|VT_BSTR;
pNamesArray->parray = SafeArrayCreate(VT_BSTR,1,rgaBound);
if (pNamesArray->parray == NULL)
{ // allocation failed
return(E_OUTOFMEMORY);
}
long i = 0;
for (iter = m_ComponentNames.begin();iter!=m_ComponentNames.end();iter++
)
{
CComBSTR bstr = iter->c_str();
SafeArrayPutElement(pNamesArray->parray,&i, bstr);
i++;
}
return S_OK;
}
------------------------------------------------------
VB Client:
Public Sub UpdateComponentNames()
Dim Experiment As NIRExperiment
Dim strNames() As String
Dim i As Integer
On Error GoTo err
Set Experiment = GetExperiment
strNames = Experiment.GetConstituentNames(m_strFileName)
' update names
......
Exit sub
- Next message: Patty O'Dors: "Re: custom licensing scheme"
- Previous message: Kyle Alons: "Re: COM API for existing C++ library"
- Next in thread: haglu: "Re: passing Safearray to VB"
- Reply: haglu: "Re: passing Safearray to VB"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|