Please help... how can I insert a bmp image in a DAO database field?
-
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
-
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
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;