PRB: Failing to Initialize OLE Generates Out of Memory Error

Last reviewed: February 17, 1998
Article ID: Q128086
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with:

        - Microsoft Visual C++ for Windows, versions 1.5, 1.51, and 1.52
        - Microsoft Visual C++, 32-bit Edition, versions 2.0, 2.1,
          4.0, 4.1, 5.0
          on the following platform: x86
    

SYMPTOMS

If the OLE .DLL files are not initialized with a call to AfxOleInit(), subsequent OLE calls will fail. For 32-bit MFC applications, debug output sent to a debugging window may show these errors:

   Throwing exception of type COleException
   sCode = 0x8007000E E_OUTOFMEMORY

   -or-

   sCode = 0x80030008 STG_E_INSUFFICIENTMEMORY

For 16-bit MFC applications, debug output may show:

   Throwing exception of type COleException
   sCode = 0x80000002 E_OUTOFMEMORY

   -or-

   sCode = 0x80030008 STG_E_INSUFFICIENTMEMORY

RESOLUTION

AfxOleInit() calls OleInitialize(LPMALLOC), which sets the task memory allocator used by OLE. If this is not done, OLE cannot perform memory allocations and any OLE calls will fail. Placing a call to AfxOleInit() in the InitInstance() of an MFC application will fix this problem. The first few lines from the InitInstance() of HIERSVR (MFC OLE sample provided with Visual C++) below, shows the proper syntax for calling AfxOleInit().

Sample Code

/* Compile options needed: standard MFC project
*/

BOOL CServerApp::InitInstance() {
    // OLE 2.0 initialization
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
... function continues ....

STATUS

This behavior is by design.

Keywords          : MfcOLE
Technology        : kbole kbMfc
Version           : Winnet:1.5,1.51,1.52,2.0,2.1,4.0,5.0
Platform          : NT WINDOWS
Hardware          : x86
Issue type        : kbprb


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: February 17, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.