BLOB读取
short vt = ole.vt; // ole is an existed COleVariant
if (vt == (VT_ARRAY|VT_UI1))
{
CByteArray abBytes;
// Make sure it's only a single dimension
ASSERT(1==::SafeArrayGetDim(ole.parray));
// Get lower and upper bounds
long lBound, uBound;
VERIFY(S_OK==::SafeArrayGetLBound(ole.parray,&lBound));
VERIFY(S_OK==::SafeArrayGetUBound(ole.parray,&uBound));
// Number of elements in array
const int n = uBound - lBound + 1;
// Get a pointer to the byte data in the variant
BYTE *pData = 0;
VERIFY(S_OK==::SafeArrayAccessData(ole.parray,(void **)&pData));
ASSERT(0!=pData);
// Copy data from variant to CByteArray
abBytes.SetSize(n);
::CopyMemory(abBytes.GetData(),pData,n);
// Release safe array data
VERIFY(S_OK==::SafeArrayUnaccessData(ole.parray));
strRet.Format( "%s",(LPCTSTR)abBytes.GetData());
strRet = strRet.Left(n);
}
BLOB存取
COleVariant* String2Blob(CString strBlob)
{
COleVariant* pVar;
CByteArray ba;
int n = strBlob.GetLength();
BYTE* pData = new BYTE[n];
memset(pData,0,n);
memcpy(pData,strBlob.GetBuffer(strBlob.GetLength()),strBlob.GetLength());
for (int i=0;i <n;i++)
{
ba.Add(*(pData+i));
}
pVar = new COleVariant(ba);
return pVar;
}