Solved

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

Posted on 2004-10-15
5
1,180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Grammars for C C++ and java 1 147
How to split this in C++ 4 130
Better understanding on C++ Class serialization and formats 9 106
Problem with SqlConnection 4 194
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

710 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