AnnLoadArray example for C++ 4.0 and later
Note: This topic is for Document/Medical only.
void CVCLoadSampleDlg::OnAnnLoadArray()
{
long lCount;
COleVariant MyVar;
HFILE hFile;
HGLOBAL hData=NULL;
void FAR* pData=NULL;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
MyVar.Clear();
hFile = _lopen("d:\\work\\images\\a.ann", OF_READ);
lCount = _llseek(hFile, 0, SEEK_END);
_llseek(hFile, 0, SEEK_SET);
hData = GlobalAlloc(GMEM_MOVEABLE, lCount);
pData = GlobalLock(hData);
_lread(hFile, pData, lCount);
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lCount;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
SafeArrayLock(psa);
memcpy(psa->pvData, pData, lCount);
unsigned int uCopy;
unsigned long dwBytes;
unsigned char *pDst=NULL;
unsigned char *pSrc=NULL;
pDst = (unsigned char *)psa->pvData;
pSrc = (unsigned char *)pData;
dwBytes = lCount;
while (dwBytes)
{
uCopy = (unsigned int) min (dwBytes, 0x0FFFEUL);
memcpy(pDst, pSrc, uCopy);
dwBytes -= uCopy;
pDst += uCopy, pSrc += uCopy;
}
SafeArrayUnlock(psa);
V_VT(&MyVar) = (VT_ARRAY | VT_UI1);
V_ARRAY(&MyVar) = psa;
GlobalUnlock(hData);
GlobalFree(hData);
m_Lead1.AnnLoadArray(MyVar, lCount, 1);
m_Lead1.SetAnnUserMode(ANNUSERMODE_DESIGN);
_lclose(hFile);
}