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