Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please help... how can I insert a bmp image in a DAO database field?

Please help... how can I insert a bmp image in a DAO database field?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasehelp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jose Luis
    wrote on last edited by
    #1

    Hi, firstly sorry for my English but it isn`t my own language. I have to insert a bmp image in a database field, but I can´t. I have done the database with DAO and dynamic style (using the Get/SetFieldValue functions), and with VARIANT data type. I want to insert the bmp through a field (of CLongBinary or CByteArray style) of a dialog box but I don`t know why I can`t do it. Thanks, José :confused: Jose

    M 1 Reply Last reply
    0
    • J Jose Luis

      Hi, firstly sorry for my English but it isn`t my own language. I have to insert a bmp image in a database field, but I can´t. I have done the database with DAO and dynamic style (using the Get/SetFieldValue functions), and with VARIANT data type. I want to insert the bmp through a field (of CLongBinary or CByteArray style) of a dialog box but I don`t know why I can`t do it. Thanks, José :confused: Jose

      M Offline
      M Offline
      Masaaki Onishi
      wrote on last edited by
      #2

      Hello, the codegurus around the world.;) I remebered to read some article for this in MSDN help, so I try to find this. Unfortunately, I didn't find the same one, but found some tips. I don't know how to convert bitmap file to BYTE format, but I expect that this will help you?

      HOWTO: Accessing Binary Data Using dbDao


      The information in this article applies to:

      Microsoft Visual C++, 32-bit Editions, versions 4.0, 4.1, 4.2, 4.2b, 5.0, 6.0


      SUMMARY
      When using the DAO SDK C++ classes to access binary data (such as a bitmap) you will find
      that the data is returned in a COleVariant. COleVariant is an MFC class that wraps the
      OLE VARIANT data type. Within the VARIANT, the data is stored as an OLE SAFEARRAY.

      Extracting the binary data from the COleVariant requires some knowledge of VARIANTs and
      SAFEARRAYs. The sample code below illustrates how to work with these data types by providing
      a function for extracting binary data from a COleVariant and a function for storing binary data in a COleVariant.

      MORE INFORMATION

      Sample Code

      //Extensive error checking is left out 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;
      
      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups