Solved

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

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

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
Writing a parser for java language 4 83
Socket Programming (Unix) 8 141
Using Diagnostic tools in VS2015: Unresoved allocations 19 105
object oriented programming comparison 5 77
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

856 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