Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
How do I use MFC class CLongBinary with COleVariant?
I'm working on this project at work: my program will extract data from a Palm Pilot, and enter them into an Access *.mdb file. Everything is working fine up until I have to set images into the database. Based on the documentation I've read on MSDN website, I have to create a CLongBinary object and associate it with the HGLOBAL which is the loaded image, and then create a COleVariant object, passing the CLongBinary object in the constructor. I received a "This program has performed an illegal operation" error. MSVCRT.DLL is the culprit of the error, and upon debugging the program, I found out that there was a call to memcpy() and it was given a null-pointer (char* 0x00000000) as the source to copy memory from. I know that the constructor of COleVariant makes a copy of the object passed to it, which justifies the call to memcpy. I don't understand why it would try to copy from mem address 0x0000000. Am I just using these classes all wrong, or is there a better way to do this? MSDN recommended using CByteArray instead of CLongBinary but it's seem more confusing to me. Any help would be appreciated.
Here's what the code looks like:
HBITMAP hPic = (HBITMAP)LoadImage(NULL,"filename",IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);
clb.m_hData = hPic;
clb.m_dwDataLength = 294966; //size of the image
COleVariant oleImage(clb); //this is where the program crashes
0 · ·