ADO的GetChunk后VARIANT转换问题

xuxingok 2007-07-12 11:15:43
数据库是ACCESS的ADO连接
在表中有个OLE对象的字段,字段名ParamInfo

unsigned char cParamInfo[PARAMSIZE];
memset(cParamInfo, 0x00, PARAMSIZE * sizeof(unsigned char));

// 对数据库进行写
VARIANT varBLOB;
::VariantInit(&varBLOB);
SAFEARRAY *psa = NULL;
SAFEARRAYBOUND rgsabound[1];
m_pRecordset->AddNew();
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = PARAMSIZE;
psa = ::SafeArrayCreate(VT_UI1, 1, rgsabound);
// 到这在这里cParamInfo就是直接写进PARAMSIZE个0的
for (long index = 0; index < PARAMSIZE; ++index)
::SafeArrayPutElement(psa, &i, cParamInfo + index);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
m_pRecordset->GetFields()->GetItem("ParamInfo")->AppendChunk(varBLOB);
m_pRecordset->Update();

// 对数据库进行读
VARIANT varBLOB;
::VariantInit(&varBLOB);
long lDataSize = 0l;

lDataSize = m_AdoConn.m_pRecordset->GetFields()->GetItem("ParamInfo")->ActualSize;
if (PARAMSIZE == lDataSize)
{
varBLOB = m_AdoConn.m_pRecordset->GetFields()->GetItem("ParamInfo")->GetChunk(PARAMSIZE);
if(varBLOB.vt == (VT_ARRAY | VT_UI1))
{
// for(long index=0; index < PARAMSIZE; ++index)
// {
// ::SafeArrayGetElement(varBLOB.parray, &index, cParamInfo + index);
// }

unsigned char *pBuf = NULL;
HRESULT hr = ::SafeArrayAccessData(varBLOB.parray, (void **)&pBuf);
if (FAILED(hr))
{
return;//-----------------------------------(1)
}
::SafeArrayUnaccessData(varBLOB.parray);
memcpy(cParamInfo, pBuf, PARAMSIZE);
}
}

--------------------------------------------------------------------
写是成功了,没有异常;
可以在读时到(1)处就返回了,为什么会这样呢?难道GetChunk时有问题??
SafeArrayAccessData怎么会失败呢?我以前用过的都好用的啊~~~
3x
...全文
204 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxingok 2007-07-16
  • 打赏
  • 举报
回复
问题解决,给分~
CathySun118 2007-07-15
  • 打赏
  • 举报
回复
太长了,你参考下:http://www.binzi.net/html/vc/2006/0818/5946.html
xuxingok 2007-07-13
  • 打赏
  • 举报
回复
没人遇到过吗
lyg_zy 2007-07-12
  • 打赏
  • 举报
回复
用COleSafeArray试试,用法自己看MSDN
xuxingok 2007-07-12
  • 打赏
  • 举报
回复
up
xuxingok 2007-07-12
  • 打赏
  • 举报
回复
现在是GetChunk后varBLOB.parray的cElements与lLbound获取的值就是不对的,不知道是GetChunk的问题还是AppendChunk的问题~~~

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧