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 strongm 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 the data in a safearray?

Status
Not open for further replies.

cathym

Programmer
Jul 17, 2002
25
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.
 
Here is some example code that I used to send and receive bytes of data through a serial port. I used safe arrays to retrieve the data from the receive buffer.

// Receive data message via serial port
// Must store "data messages" in a SafeArray variable
HRESULT hr;
long lLen;
BYTE* pAccess;

// If everything IS in sync...
m_dataVar.Attach(m_MSComm.GetInput());
hr = SafeArrayGetUBound(m_dataVar.parray, 1, &lLen);
if (hr == S_OK)
{
// Upper bound is a Zero based index
lLen++;
// Lock array so you can access it
hr = SafeArrayAccessData(m_dataVar.parray, (void**)&pAccess);
// If correct array is OK... Update screen
// Be sure to detach the data afterwards to prevent data overflow
if ((hr==S_OK))
{
////////////////////////////////////////////
// Manipulate pAccess array however you want
////////////////////////////////////////////

// Detach and unlock the data to allow for next update
m_dataVar.Detach();
SafeArrayUnaccessData(m_dataVar.parray);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top