Solved

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

Posted on 2004-10-15
5
1,175 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

685 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