1、将double类型的数据存储于image类型的变量中:
(1)、
char *CManualForecastResultBll::DoubleArray2Binary(std::vector &doubleArray)
{
int len = doubleArray.size();
char *bin = new char[len * sizeof(double)];
unsigned __int64 *p = (unsigned __int64*)bin;
for (int i = 0; i < len; i++)
{
*p = DOUBLE2UINT64(doubleArray.at(i));
p++;
}
return bin;
}
unsigned __int64 CManualForecastResultBll::DOUBLE2UINT64(double v)
{
unsigned __int64 *pu64n = NULL;
pu64n = reinterpret_cast(&v);
return *pu64n;
}
(2)、
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = (ULONG)(pData->qLen);
psa = SafeArrayCreate(VT_UI1, 1, rgsabound);
byte * pQt = pData->QTLINE; //自己的数据byte类型
for (long i = 0; i < pData->qLen; i++)
SafeArrayPutElement (psa, &i, pQt++);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
pRecordset->GetFields()->GetItem(SimulateResultDataFeilds[i])->AppendChunk(varBLOB);
2、根据已知image类型中存储的数据类型(例如:double、float等)取数据:
case VT_ARRAY | VT_UI1:
Binary2DoubleArray(vtFld);
break;
//
void DBRecordset::Binary2DoubleArray(_variant_t vtFld)
{
int len = vtFld.parray->rgsabound->cElements / sizeof(double);
double *pdata = new double[len];
/*int len = vtFld.parray->rgsabound->cElements / sizeof(float);
float *pdata = new float[len];*/
SafeArrayAccessData(vtFld.parray, (void**)&pdata);
/*unsigned __int64 *pu64n = new unsigned __int64[len];
SafeArrayAccessData(vtFld.parray, (void**)&pu64n);*/
ofstream writetofile("image.txt");
for (int i = 0; i < len; i++)
{
if (i % 30 == 0 && i != 0)
{
writetofile<
}
writetofile<
//writetofile<(&pu64n[i]))<
writetofile.flush();
}
writetofile<
writetofile.close();
SafeArrayUnaccessData(vtFld.parray);
}