Solved

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

Posted on 2004-10-15
5
1,155 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
ID: 12320182
What is the HRESULT code after it fails?
0
 
LVL 3

Author Comment

by:stu_pb
ID: 12320221
The result is E_OUTOFMEMORY (-2147024882).
0
 
LVL 86

Expert Comment

by:jkr
ID: 12320251
Sorry :o)

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

Accepted Solution

by:
stu_pb earned 0 total points
ID: 12320759
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

776 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