Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1094
  • Last Modified:

OleLoadPicturePath() creates a referenced memory error when program finishes execution

My problem is that, i'm receiving an error when my program finishes execution.  The program executes as it should, but once the program has finished, I get a Memory Reference Error. Trying to find where that error comes from, I realized that commenting out the OleLoadPicturePath() function solve my problem. I do not get this error message at the shutdown of my application anymore:

 "The instruction at 'ox7c9100e8' referenced memory at '0x011c0010'. The memory could not be 'read'."

Unfortunately, removing this function is not an option as it is needed for the proper behaviour of the program. I tried using a procedure with the oleLoadPicture() function but I get the same problem. This part of the program basically tries to load a Jpeg picture and convert it to an uncompressed RGBA bitmap 32 bit picture.

Here is a part of the code. Just having those lines creates the problem. I know those lines don't make much sense, I commented/removed everything that was not relevant to the problem happening :

bool LoadJPG(tstring fileName)
{
      long lWidth;
      long lHeight;

    if (m_pIPicture != NULL)
      {
            m_pIPicture->Release();
        m_pIPicture = NULL;
      }

      //Commenting this line makes the referenced memory problem go away
      HRESULT hr = OleLoadPicturePath(T2OLE((LPTSTR)fileName.c_str()), NULL, 0, 0, IID_IPicture, (LPVOID *)&(m_pIPicture));

      if (m_pIPicture != NULL)
      {
            m_pIPicture->Release();
        m_pIPicture = NULL;
      }

      lWidth  = 1920;
      lHeight = 1080;

      unsigned char *pImageBitmapData = (unsigned char *)new (nothrow) unsigned char[lWidth * lHeight * 4];
      if (!pImageBitmapData)
      {
            TCHAR errorMsg[255];
            _stprintf(errorMsg, _T("Failed to load '%s'! - Out of memory!"), fileName.c_str());
            MessageBox(NULL, errorMsg, _T("ERROR"), MB_OK);

            return (false);
      }
      memset(pImageBitmapData, 11, lWidth * lHeight * 4);

      m_uiImageBitmapWidth = lWidth;
      m_uiImageBitmapHeight = lHeight;
      // We have created a 32-bit (RGBA) image
      m_ucImageBitmapBitsPerPixel = 4;
      m_pImageBitmapData = pImageBitmapData;

      return (true);
}
 
 
  Am I missing something? Is there something else to release than the LPPICTURE for a proper shutdown of the application? Is there pre/post procedure
  to implement before the call of this Object Linking and Embedding (OLE) function that I am not aware of?
  Thank You in advance for your help!
0
IBruteforce
Asked:
IBruteforce
1 Solution
 
IBruteforceAuthor Commented:
Hi , I solved my problem by implementing my solution using the GDI+ API with the image encoder/decoder instead of using OLE function.  Much simpler and more powerful in my opinion.

Info on GDI+ encoder/decoder can be found here :
http://msdn.microsoft.com/en-us/library/bb882579.aspx
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now