access存入图像,内存不知道怎么释放问题
大头猫 2011-09-25 11:16:34 //1刷新获取表名,图片名字
UpdateData();
//2链接指定的表
Init_Data(m_pConnection_store, m_pRecordset_store,m_list_name);
//3进行指定图片的存储
BYTE* pBufForSavePhoto=NULL;
CFile file;
if(!file.Open(m_pic_name,CFile::modeRead))
{
return;
}
long nLength= (long)file.GetLength();
pBufForSavePhoto = new BYTE[nLength+2] ;
if(pBufForSavePhoto==NULL)
{
AfxMessageBox(TEXT("内存申请出错"));
return ;//allocate memory error
}
else
{
file.Read(pBufForSavePhoto,nLength);
file.Close();
//build a SAFFERRAY
VARIANT varBLOB;
SAFEARRAY* psa ;
SAFEARRAYBOUND rgsabound[1];
rgsabound[0].lLbound=0;
rgsabound[0].cElements=nLength;
psa=SafeArrayCreate(VT_UI1,1 ,rgsabound);
for(long lLength = 0 ;lLength<nLength;lLength++)
{
SafeArrayPutElement(psa,&lLength,pBufForSavePhoto++) ;
} // end of for
varBLOB.vt=VT_ARRAY| VT_UI1;
varBLOB.parray = psa;
m_pRecordset_store->AddNew();
m_pRecordset_store->GetFields()->GetItem("pic_name")->Value=(_variant_t)m_pic_name;
m_pRecordset_store->GetFields()->GetItem("pic_x")->Value=m_pos_x;
m_pRecordset_store->GetFields()->GetItem("pic_y")->Value=m_pos_y;
m_pRecordset_store->GetFields()->GetItem("pic_struct")->AppendChunk(varBLOB);///加入BLOB类型
m_pRecordset_store->Update();
//
}
//释放内存]