Available in the LEADTOOLS Imaging toolkit. |
LoadArray example for C++ 4.0 and later
long lCount;
COleVariant MyVar;
HFILE hFile;
HGLOBAL hData=NULL;
void FAR* pData=NULL;
SAFEARRAY FAR *psa;
SAFEARRAYBOUND rgsabound[1];
MyVar.Clear();
hFile = _lopen("d:\\temp\\test.cmp", 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);
#ifdef WIN32
memcpy(psa->pvData, pData, lCount);
#else
unsigned int uCopy;
unsigned long dwBytes;
unsigned char _huge *pDst=NULL;
unsigned char _huge *pSrc=NULL;
pDst = (unsigned char _huge *)psa->pvData;
pSrc = (unsigned char _huge *)pData;
dwBytes = lCount;
while (dwBytes)
{
uCopy = (unsigned int) min (dwBytes, 0x0FFFEUL);
_fmemcpy(pDst, pSrc, uCopy);
dwBytes -= uCopy;
pDst += uCopy, pSrc += uCopy;
}
#endif
SafeArrayUnlock(psa);
V_VT(&MyVar) = (VT_ARRAY | VT_UI1);
V_ARRAY(&MyVar) = psa;
GlobalUnlock(hData);
GlobalFree(hData);
m_LEAD1.LoadArray(MyVar, 0, 0, -1, lCount);
_lclose(hFile);