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

Posted on 2009-04-24
Last Modified: 2013-12-14
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 = 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 = 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!
Question by:IBruteforce
    1 Comment

    Accepted Solution

    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 :

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Suggested Solutions

    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now