Microsoft KB Archive/128086

= 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

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.52 Professional Edition

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 6.0 Professional Edition</li></ul>

 Microsoft Visual C++ 6.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q128086

<div class="symptoms_section">

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

<div class="resolution_section">

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 ....

<div class="status_section">

STATUS
This behavior is by design.

Keywords: kbtshoot kbprb KB128086

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.