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
- Microsoft Visual C++ 4.0 Standard Edition
- Microsoft Visual C++ 4.1 Subscription
- Microsoft Visual C++ 5.0 Enterprise Edition
- Microsoft Visual C++ 5.0 Professional Edition
- Microsoft Visual C++ 6.0 Enterprise Edition
- Microsoft Visual C++ 6.0 Professional Edition
- Microsoft Visual C++ 6.0 Standard Edition
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