if(FAILED(picRs->AddNew(&rs))) |
//写入一张照片到数据库: VARIANT varChunk; SAFEARRAY *psa; SAFEARRAYBOUND rgsabound; //VT_ARRAY │ VT_UI1 CFile f("h:\\aaa.jpg",Cfile::modeRead); BYTE bVal[ChunkSize+1]; UINT uIsRead=0; //Create a safe array to store the array of BYTES while(1) { uIsRead=f.Read(bVal,ChunkSize); if(uIsRead==0)break; rgsabound[0].cElements =uIsRead; rgsabound[0].lLbound = 0; psa = SafeArrayCreate(VT_UI1,1,rgsabound); for(long index=0;index if(FAILED(SafeArrayPutElement(psa,&index,&bVal[index]))) ::MessageBox(NULL,"啊,又出毛病了。","提示",MB_OK │ MB_ICONWARNING); } varChunk.vt = VT_ARRAY│VT_UI1; varChunk.parray = psa; try{ m_pRecordset->Fields->GetItem("photo")->AppendChunk(varChunk); } catch (_com_error &e) { CString str=(char*)e.Description(); ::MessageBox(NULL,str+"\n又出毛病了。","提示",MB_OK │ MB_ICONWARNING); } ::VariantClear(&varChunk); ::SafeArrayDestroyData( psa); if(uIsRead f.Close(); //从数据库读一张照片: CFile f; f.Open("h:\\bbb.jpg",Cfile::modeWrite│Cfile::modeCreate); long lPhotoSize = m_pRecordset->Fields->Item["photo"]->ActualSize; long lIsRead=0; _variant_t varChunk; BYTE buf[ChunkSize]; while(lPhotoSize>0) { lIsRead=lPhotoSize>=ChunkSize? ChunkSize:lPhotoSize; varChunk = m_pRecordset->Fields-> Item["photo"]->GetChunk(lIsRead); for(long index=0;index ::SafeArrayGetElement(varChunk.parray,&index,buf+index); } f.Write(buf,lIsRead); lPhotoSize-=lIsRead; }//while() f.Close(); |