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. Save a File from Variant

Save a File from Variant

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasequestion
3 Posts 3 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 Fco Bonnin
    wrote on last edited by
    #1

    Hello, I have an ATL object which loads a JPEG from database in a VARIANT now I need to save the variant to a file on disk. Any idea? Thanks.

    T D 2 Replies Last reply
    0
    • J Jose Fco Bonnin

      Hello, I have an ATL object which loads a JPEG from database in a VARIANT now I need to save the variant to a file on disk. Any idea? Thanks.

      T Offline
      T Offline
      TyMatthews
      wrote on last edited by
      #2

      How far have you gotten with the variant? Can you post the code you have? I have sample code that does this with ADO, but I need to know where you're at.     Ty

      "The significant problems we face cannot be solved at the same level of thinking we were at when we created them." -Albert Einstein

      1 Reply Last reply
      0
      • J Jose Fco Bonnin

        Hello, I have an ATL object which loads a JPEG from database in a VARIANT now I need to save the variant to a file on disk. Any idea? Thanks.

        D Offline
        D Offline
        dabs
        wrote on last edited by
        #3

        Assuming you have the variant containing the data then this function will extract the data and put it into *ppBuf: bool GetBinaryFromVariant( VARIANT& vData, BYTE ** ppBuf, unsigned long * pcBufLen ) { bool bReturn = false; //Binary data is stored in the variant as an array of unsigned char if( vData.vt == ( VT_ARRAY|VT_UI1 ) ) { //Retrieve size of array *pcBufLen = vData.parray->rgsabound[0].cElements; //Allocate a buffer to store the data *ppBuf = new BYTE[*pcBufLen]; if(*ppBuf != NULL) { void* pArrayData; //Obtain safe pointer to the array SafeArrayAccessData(vData.parray,&pArrayData); //Copy the bitmap into our buffer memcpy(*ppBuf, pArrayData, *pcBufLen); //Unlock the variant data SafeArrayUnaccessData(vData.parray); bReturn = true; } } return bReturn; } Then you would use it like this - the code is from the top of my head so I'm not sure it will compile or work correctly :-) BYTE* pBuffer = NULL; UINT nBufSize = 0; if ( GetBinaryFromVariant( vtJPEG, &pBuffer, &nBufSize ) ) { //Safe the buffer to file: CFile file; if ( file.Open( strTheFileName, CFile::modeCreate | CFile::modeTruncate ) ) { file.Write( pBuffer, nBufSize ); } delete [] pBuffer; }


        Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!

        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