-
October 28th, 2004, 10:04 AM
#1
Variant And Safearray
why in this part of the code ....after adding the safearray of BSTR's to the Variant...
when i try to fetch the contents of the variant ..it returns empty values?
std::map<int,CString> bsVector;
std::map<int,CString>::iterator iter;
CReadExcel excel;
_bstr_t filename="C:\\test3.xls";
std::vector<CString>vector;
excel.ExtractFormulaFromExcel(filename,bsVector);
BSTR * bstrValTemp=bstrVal;
for(iter=bsVector.begin(); iter!=bsVector.end();iter++)
{
_bstr_t bstrFinal(iter->second);
*bstrValTemp++=bstrFinal.copy();
}
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = bsVector.size();
VariantInit(&m_vtSource);
VARIANT vtTarget;
VariantInit(&vtTarget);
m_vtSource.vt = VT_BSTR | VT_ARRAY;
m_vtSource.parray = SafeArrayCreate(VT_BSTR,1,rgsabound);
for(long k=0;k<bsVector.size();k++)
SafeArrayPutElement(m_vtSource.parray,&k,bstrVal[k]);
try
{
HRESULT hr;
_bstr_t* pData;
int count=int(m_vtSource.parray->cbElements);
hr = SafeArrayAccessData(m_vtSource.parray, (void**)&pData); //access the array stored in the varriant.
for(int i = 0; i < count; i++)
{
_bstr_t bst(pData[i]);
AfxMessageBox((LPCTSTR)bst.copy());
}
SafeArrayUnaccessData(m_vtSource.parray);
//HRESULT hr=mapInterface->RetrieveTargetFormula(src,m_vtSource,&bstr,&vtTarget);
}
catch(...)
{
mapInterface->Release();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|