Solved

CoCreateInstance fails in debug mode but works in release...

Posted on 2004-10-15
5
1,127 Views
Last Modified: 2012-05-05
I have a windows service that creates an instance of an ATL COM object using CoCreateInstance.  When the ATL COM object is compiled in DEBUG mode that service can successfully create an instance, however when the COM object is compiled in RELEASE mode the call to CoCreateInstance fails with the code E_OUT_OF_MEMORY.

In the service I include the object.h and object_i.c files. I also link to the object.lib file.

ILPS* pLPS = NULL;                  // Pointer to the LPS interface
CLSID clsid;                  // The CLSID of the LPS interface
HRESULT hr;            // Error Code for COM

CoInitialize(0);            // This must be called for every thread

// Get the CLSID of the LPS interface
hr = CLSIDFromProgID(OLESTR("LPSCORE.LPS"),&clsid);
if (FAILED(hr))
      goto cleanup;

// Create an instance of the LPS interface
hr = CoCreateInstance(clsid,NULL,CLSCTX_SERVER,IID_ILPS,(void**)&pLPS);
if (FAILED(hr))
      goto cleanup;

I have checked the registry after building in both modes and it looks right!

Anyone have this happen to them before, or know what is causing this?

Thanks!
0
Comment
Question by:stu_pb
  • 2
  • 2
5 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
What is the HRESULT code after it fails?
0
 
LVL 3

Author Comment

by:stu_pb
Comment Utility
The result is E_OUTOFMEMORY (-2147024882).
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Sorry :o)

Could you post the code for the ATL object also?
0
 
LVL 3

Accepted Solution

by:
stu_pb earned 0 total points
Comment Utility
I found it!

There is an exception thrown in the constructor of the object.  In release mode the exception is caught successfully and processed, but in debug mode the exception is not caught and the object fails to be created.

Thanks for your helping!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now