BinaryValues2 Example for C++ 6.0 and later

void GetSetPrivateData(ILEADDicomDSPtr spDataSet)
{
   long nPrivateDataTag = 0x19100E;
   SAFEARRAY* psaPrivateData = NULL;
   unsigned char *piData = NULL;
   IDicomDSElementPtr pCurrentElement = NULL;

   VARIANT vPrivateData;
   long nCount;
   int nIndex;
   int nDicomRet;

   spDataSet->EnableMethodErrors = FALSE;
   // I am assuming that the dataset already includes the private element
   nDicomRet = spDataSet->FindFirstElement(nPrivateDataTag, FALSE);
   if(nDicomRet != 0)
      return;

   //get the byte count
   pCurrentElement = spDataSet->CurrentElement();
   nCount = pCurrentElement->GetLength();
   if(nCount == 0)
      return;  

   //get the data
   nDicomRet = spDataSet->GetBinaryValue(nCount);
   if(nDicomRet != 0)
      return;  
   VariantInit(&vPrivateData);
   spDataSet->get_BinaryValues2(&vPrivateData);  
   //Remap the data
   psaPrivateData = (SAFEARRAY*)V_ARRAYREF(&vPrivateData);
   SafeArrayAccessData(psaPrivateData, (void HUGEP* FAR *) &piData);
   for(nIndex =0; nIndex <= (nCount-1); nIndex++)
   {
      piData[nIndex] = piData[nIndex] + 1;
   }
   //put the data back
   SafeArrayUnaccessData(psaPrivateData);
   spDataSet->put_BinaryValues2(vPrivateData);
   SafeArrayDestroy(psaPrivateData);
   spDataSet->SetBinaryValue(nCount);
}