Mosquito 132 How to combine cmenfile with CArchive for efficient sequencing ...

Source: Internet
Author: User
Tags ole

Source: Mosquito 132 How to combine cmenfile with CArchive for efficient sequencing ...

Serial number storage is our usual way of storing files, mosquito 132 This article describes how to combine cmenfile with CArchive for efficient serial number storage.
BYTE * PPBUF;
Long Pcbuflen;
CMemFile file (Ppbuf,pcbuflen);
CArchive ar (&file,carchive::load);
Convert CArchive and COleVariant to a large segment of the database in memory files
Here is the COleVariant with byte conversion:
Extensive error checking is left off to make the code more readable

BOOL getbinaryfromvariant (COleVariant & Ovdata, BYTE * * ppbuf,
unsigned long * pcbuflen)
{
BOOL fretval = FALSE;

Binary data is stored in the variant as an array of unsigned char
if (OVDATA.VT = = (vt_array| VT_UI1))//(OLE SAFEARRAY)
{
Retrieve size of array
*pcbuflen = ovdata.parray->rgsabound[0].celements;

*ppbuf = new Byte[*pcbuflen]; Allocate a buffer to store the data
if (*ppbuf! = NULL)
{
void * PARRAYDATA;

Obtain safe pointer to the array
Safearrayaccessdata (Ovdata.parray,&parraydata);

Copy the bitmap into our buffer
memcpy (*ppbuf, Parraydata, *pcbuflen);

Unlock the Variant data
Safearrayunaccessdata (Ovdata.parray);
fRetVal = TRUE;
}
}
return fretval;
}

BOOL putbinaryintovariant (COleVariant * ovdata, BYTE * PBuf,
unsigned long Cbuflen)
{
BOOL fretval = FALSE;

VARIANT var;
VariantInit (&var); Initialize Our variant

Set the type to an array of unsigned chars (OLE SAFEARRAY)
VAR.VT = Vt_array | VT_UI1;

Set up the bounds structure
Safearraybound rgsabound[1];

Rgsabound[0].celements = Cbuflen;
Rgsabound[0].llbound = 0;

Create an OLE SAFEARRAY
Var.parray = SafeArrayCreate (Vt_ui1,1,rgsabound);

if (var.parray! = NULL)
{
void * Parraydata = NULL;

Get a safe pointer to the array
Safearrayaccessdata (Var.parray,&parraydata);

Copy Bitmap to it
memcpy (Parraydata, PBuf, Cbuflen);

Unlock the Variant data
Safearrayunaccessdata (Var.parray);

*ovdata = var; Create a colevariant based on our variant
VariantClear (&var);
fRetVal = TRUE;
}

return fretval;
}


How to might call these functions

Cdbrecordset rs;

Code for initializing DAO and opening the recordset left out ...

COleVariant ovdata = Rs. GetField (_t ("Mybinaryfield"));

BYTE * PBuf = NULL;
unsigned long Cbuflen;

if (Getbinaryfromvariant (Ovdata,&pbuf,&cbuflen))
{
Do something with binary data in PBuf ...

Write back a new record containing the binary data

COleVariant ovData2;
if (Putbinaryintovariant (&ovdata2,pbuf,cbuflen))
{
Rs. AddNew ();
Rs. SetField (_t ("Mybinaryfield"), OVDATA2); Write our COleVariant
to the table
Rs. Update ();
}
Clean up memory allocated by getbinaryfromvariant
if (PBUF)
Delete PBuf;
Copy the Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.