Extra reference after opening a file

D

David Liebtag

I am having trouble with an unexplained extra reference to Excel. I'm
hoping someone here can explain.

Here is some pseudo-code that illustrates what my code (that is written in
C) is doing:

IDIspatch * Dispatch
IDIspatch * Workbooks
IDIspatch * File
CoCreateInstance ("Excel.Application,&IDispatch)
Workbooks = PropertyGet(IDispatch,"Workbooks")
File = Invoke(Workbooks,"Open","d:\test.xls")
Workbooks::Release
File::Release
IDispatch::Release

After my program terminates, I see in the XP Task Manager that an instance
of Excel is still running. This does not happen if I skip the Open and
related Release steps.

Can anyone explain why Excel is still running?

Thanks in advance.

David Liebtag
 
T

Tom Ogilvy

In VB, this is usually because of an unreleased reference. I don't know
anything about C and COM, but I would release in the opposite order that I
created

IDIspatch * Dispatch
IDIspatch * Workbooks
IDIspatch * File
CoCreateInstance ("Excel.Application,&IDispatch)
Workbooks = PropertyGet(IDispatch,"Workbooks")
File = Invoke(Workbooks,"Open","d:\test.xls")
File::Release
Workbooks::Release
IDispatch::Release

I have reversed the release of File and Workbook.
 
D

David Liebtag

I solved the problem. The Open method returns a Workbook object. You have
to call the Workbook's Close method before releasing it.

David Liebtag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top