You receive out-of-memory error messages when OLE calls fail if the OLE DLLs are not initialized by using a call to the AfxOleInit function (128086)



The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), when used with:
    • Microsoft Visual C++ for Windows, 16-bit edition 1.5
    • Microsoft Visual C++ for Windows, 16-bit edition 1.51
    • Microsoft Visual C++ for Windows, 16-bit edition 1.52
    • Microsoft Visual C++, 32-bit Editions 2.0
    • Microsoft Visual C++, 32-bit Editions 2.1
    • Microsoft Visual C++, 32-bit Editions 4.0
    • Microsoft Visual C++, 32-bit Editions 4.1
    • Microsoft Visual C++, 32-bit Enterprise Edition 5.0
    • Microsoft Visual C++, 32-bit Professional Edition 5.0
    • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
    • Microsoft Visual C++, 32-bit Professional Edition 6.0
    • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q128086

SYMPTOMS

If the OLE .DLL files are not initialized with a call to the AfxOleInit function, subsequent OLE calls will fail. For 32-bit MFC applications, debug output sent to a debugging window may display one of the following error messages:
Throwing exception of type COleException
sCode = 0x8007000E E_OUTOFMEMORY
sCode = 0x80030008 STG_E_INSUFFICIENTMEMORY
For 16-bit MFC applications, debug output may display one of the following messages:
Throwing exception of type COleException
sCode = 0x80000002 E_OUTOFMEMORY
sCode = 0x80030008 STG_E_INSUFFICIENTMEMORY

RESOLUTION

The AfxOleInit function 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 the AfxOleInit function 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 describes the correct syntax for calling the AfxOleInit function.

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.

Modification Type:MajorLast Reviewed:9/1/2005
Keywords:kbtshoot kbprb KB128086