Knowledge Base

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

Article ID: 128086

Article Last Modified on 11/21/2006


APPLIES TO


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.

Keywords: kbtshoot kbprb KB128086