Serialization to a CDaoRecordset field 
Author Message
 Serialization to a CDaoRecordset field

I would like to serialize an object to an OLE object field of a JET table.
Is this possible? Do you know how to do it? If so I would be so
appreciative if you could send me some sample code or point me to the
right direction. I have been digging through my MSDN Oct96 CD and have not
found an explanation of how this is done. I've been working on this
problem for many days. Below I have given an overview of what I have come
up with so far.. and then the actual code I have written. Please help if
you can.

Overview:

     class CAnimal : public Cobject
         |
         |      (CAnimal::Serialize writes to a CArchive
        \|/      associated with a CMemFile)
     CArchive arcMy;
     CMemFile mfMy;
         |
         |    pbMy = mfMy.Detach;
         |    (CMemFile::Detach obtains a pointer to the memory block)
        \|/    
     BYTE* pbMy;                
         |   (???? This is unknown. I need to get the block of memory
         |     pointed to by pbMy into a COleVariant so that it can be
         |    written to a field of a CDaoRecordset with ::SetFieldValue.
         |    Ive tried unsuccesfully to set BSTR = a copy of *pbMy with
        \|/     SysAllocString. Please help me here.
     COleVariant vntOLE;
         |
         |    (rstMy.SetFieldValue(1, &vntOLE))
        \|/  
     CDaoRecordset rstMy;    

Code:

     //create the object and set one member variable
     CAnimal aniMy;
     aniMy.SizeSet(5);

     //write the object to a CMemFile
     CMemFile mfMy;
     CArchive arcMy(&mfMy, CArchive::store);
     aniMy.Serialize(arcMy);
     arcMy.Close;

     //detach the block of memory of the CMemFile
     BYTE* pbmfMy;
     pbmfMy = mfMy.Detach();

     //failing attempt to copy the block of memory to a new COleVariant.
     COleVariant vntOle;                        
     vntOle.vt = VT_BSTR;                      
     LPCTSTR lpszMy;
     lpszMy = pbmfMy;   <-- This fails to compile
     vntOle.bstrVal = SysAllocString(*lpszMy);  <--This fails to compile

     //set a field of a CDaoRecordset to contain the COleVariant
     prstMy->Edit;
     prstMy->SetFieldValue(1, &vntOLE);
     prstMy->Update;

     //free the BSTR
     SysFreeString(*lpszMy); <--This fails to compile

--
TIA
Michael J. Freeman



Thu, 08 Jul 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Serialization to a CDaoRecordset field

2. CDaoRecordSet -- CDaoRecordSet -- CDaoRecordSet

3. how to get Field Caption From CDaoRecordset?

4. CDaoRecordset with binary field

5. CDAORecordset & BLOBS/memo fields

6. Filling a CDaoRecordset field of type OLE object from VC++

7. How to Write a 0-Embeded String to a CDaoRecordSet text field

8. Help!! AutoIncrement fields and CDaoRecordset

9. Copy fields in a CDaoRecordset?

10. Cannot open a CDAORecordset without correct field

11. CDaoRecordset::Seek and multi-field indexes

12. calculated fields with CDaoRecordset

 

 
Powered by phpBB® Forum Software