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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you use safearrays???

Status
Not open for further replies.

cathym

Programmer
Jul 17, 2002
25
0
0
US
I'm new to automation. I have my wrapper for excel, and I can fill the safearray. Now I need to manipulate the data before putting it back on the excel sheet, and I can't seem to access the data. So far, I have only used C++ academically. Professionally, my experience has been in VB and ASP with MTS. If anyone can help, I would appreciate it.






 
Look in MSDN:
SafeArrayGetUBound, SafeArrayGetElement, SafeArrayPutElement and other.

Small functions for manipulate safearray vectors:
void OLECreateVector(long iLen, _variant_t* pvarArr)
{
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].cElements = iLen;
rgsabound[0].lLbound = 0;

SAFEARRAY * psa = SafeArrayCreate(VT_VARIANT, 1, rgsabound);
if(psa == NULL) _com_issue_error(E_OUTOFMEMORY);

pvarArr->vt = VT_ARRAY | VT_VARIANT;
pvarArr->parray = psa;
}

long OLEVectorGetUBound(_variant_t* pvarArr)
{
long lUBound;
HRESULT hRes = SafeArrayGetUBound(pvarArr->parray, 1, &lUBound);
if(hRes != S_OK) _com_issue_error(hRes);
return lUBound;
}

void OLEVectorPutElement(_variant_t* pvarArr, long iX, _variant_t* pvarVal)
{
long Indices[1];
Indices[0] = iX;
HRESULT hRes = SafeArrayPutElement(pvarArr->parray, Indices, pvarVal);
if(hRes != S_OK) _com_issue_error(hRes);
}

void OLEVectorGetElement(_variant_t* pvarArr, long iX, _variant_t* pvarVal)
{
long Indices[1];
Indices[0] = iX;
HRESULT hRes = SafeArrayGetElement(pvarArr->parray, Indices, pvarVal);
if(hRes != S_OK) _com_issue_error(hRes);
}


---------------------------------
Konstantin
AlarIT developer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top