Reading and Writing to an OLE Object Field useing DAO 
Author Message
 Reading and Writing to an OLE Object Field useing DAO

Does anybody have any examples of writting to the a OLE Object field.  I
want to just save some data into this field, nothing to do with OLE.  I've
tried the the following piece of code

        CString TempString = "Hello";
        m_pSet->m_Description = "Changed Item2";
        strcpy((char *)m_pSet->m_Data.GetData(), TempString);
        m_pSet->m_Type = 2;

All the other fields are updated except for Data(which is a OLE Object
I found an example on CodeGuru to read a PaintBrush BMP, which work great.
But I haven't found an examples on how to write to it.
I need to be able to store some 24 Bit Bitmaps along with the database, but
these are being created directly by my app.

Anybody got any ideas or suggests ???


Wayne Gibson

Sat, 28 Apr 2001 03:00:00 GMT  
 Reading and Writing to an OLE Object Field useing DAO
Use this:

void GuardeCampoI( CBitmap *Imagen, CLongBinary *Campo, CDaoRecordset *RS ){
    BYTE* bufr= NULL;       // buffer for the bitmap struct and the bits
    BYTE* tmp= NULL;        // pointer to the start of the bits
    BITMAP bm;
    int sz= NULL;
 // Obtiene la estructura

 // ***** calculate buffer needed for the bitmap bits *****
 sz= ((bm.bmWidthBytes * bm.bmHeight) * bm.bmPlanes);

 // ***** allocate the buffer for the bitmap struct AND the bits *****
 bufr= new BYTE[sz + sizeof(BITMAP) + 1];
 memset(bufr,'\0',sz + sizeof(BITMAP) + 1);

 // ***** locate start of bits after the bitmap struct *****
 tmp= bufr + sizeof(BITMAP);

 // ***** copy the bitmap struct *****

 // ***** copy the bitmap bits *****

 // ***** get rid of previous bitmap, if needed *****

 // ***** allocate the bitmap space *****
 Campo->m_hData= GlobalAlloc(GHND,sz+sizeof(BITMAP)+1);
 tmp= (BYTE*)GlobalLock(Campo->m_hData);

 // ***** copy the bitmap into the long binary field *****
 memcpy(tmp,bufr,sz + sizeof(BITMAP));

 // ***** now, remember how big the bitmap is ******
 Campo->m_dwDataLength= sz + sizeof(BITMAP);

 // ***** required to manually indacte this field needs *****
 // ***** to be stored in the database since it changed *****

  delete[] bufr;


BOOL ValorCampoI( CBitmap *Imagen, CLongBinary *Campo ){
    BYTE* bufr= NULL;
    BYTE* tmp= NULL;
    BITMAP bm;
    int sz= 0;

 // Se elimina cualquier imagen anterior
 if( Campo->m_dwDataLength > 0 ){
  bufr= (BYTE*)GlobalLock(Campo->m_hData);
  tmp= bufr + sizeof(BITMAP);
  sz= ((bm.bmWidthBytes * bm.bmHeight) * bm.bmPlanes);
tmp );
  return( TRUE );
 return( FALSE );


Sun, 29 Apr 2001 03:00:00 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Reading and Writing to an OLE Object Field useing DAO

2. DAO: Setting OLE Object Field Value in Access DB

3. Can not read contents of field with the DAO SDK (Not MFC DAO)

4. Reading OLE structured storage documents, with OLE objects...

5. Manipulating OLE Fields in DAO

6. DAO: OLE field to CBitMap -- HELP

7. Ole Fields and extraction (DAO 3.6)

8. OLE in DAO BLOB fields

9. Manipulating OLE Fields in DAO

10. DAO: OLE field to CBitMap -- HELP

11. Read only and Read/Write object pairs

12. writing 255 to a byte field becomes NULL in DAO


Powered by phpBB® Forum Software