LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Excel is remaining resident in memory when quitting my program

I am interfacing my program to excel. I am opening a new worksheet and write in a particular sheet. When I quit the program excel closes however, excel is still visible in the Task Bar (pressing CTRL-ALT-DEL).

I have based my progam on exceldemo2000.

Please find attaced a sample code which is giving me trouble.

I have noted that the following code found in the funcion Excel_WriteString found in my file attatched would leave excel resident in memory. When I remarked this part of the code excel closed gracefully.

// Get Active Workbook Sheets
if (Error >= 0)
{
Error = Excel_GetProperty (ExcelAppHandle, NULL, Excel_AppSheets, CAVT_OBJHANDLE, &ExcelSheetsHandle);
}


// Get Sheet
if (Error >= 0)
{
Error = Excel_SheetsItem (ExcelSheetsHandle, NULL, CA_VariantInt(sheet), &ExcelWorksheetHandle);
}


What's wrong with this code then?!

Thanks
Download All
0 Kudos
Message 1 of 8
(3,289 Views)
Hello

generally a problem like this shows with whem a handle is not discarded correctly. Make sure after you done with ExcelWorksheetHandle, call CA_DiscardObjHandle() on the handle. You need to make sure you do this for any handle you create

I hope this helps

Bilal Durrani
NI
Bilal Durrani
NI
0 Kudos
Message 2 of 8
(3,289 Views)
Programming a server through ActiveX will keep the process open until you discard all of the objects you are using from the process. That means that since you are getting handles to the Sheets collection and an individual worksheet, it will not shutdown the Excel process until you discard those handles. There is no built in garbage collection to take care of cleaning up these references, you have to do it yourself. For every ActiveX handle you get back, you have to discard the handle with CA_DiscardObjHandle. If you discard the ExcelSheetsHandle and the ExcelWorksheetHandle, you should be able to shutdown the Excel process.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 3 of 8
(3,289 Views)
As far as I know I am clearing these handles in my Excel_Shutdown() function (Similar to exceldemo2000). When I used the LabWindows/CVI debugger view variable, all handles appeared to be clear.

Thanks
0 Kudos
Message 4 of 8
(3,289 Views)
As far as I know I am clearing these handles in my Excel_Shutdown() function (Similar to exceldemo2000). When I used the LabWindows/CVI debugger view variable, all handles appeared to be clear.

Thanks
0 Kudos
Message 5 of 8
(3,289 Views)
It seems that exceldemo2000 has the same problem of leaving excel resident in memory. This is happening when the following sequence of commands are made:

Once run exceldemo2000,

LaunchExcel,
OpenFile,
Read -> Will show popup [Values returned not Double]
Quit.

Can someone please show me where and why excel2000demo is not discarding the objects cause it seems that I am having the same problem and my program is entierly based on this demo.

Thanks
Raphael
0 Kudos
Message 6 of 8
(3,289 Views)
I have the same problem and have been using the
new labwindows 6.0 excelreport fp.
This is causing quite a nucance since when the application is quitting or the excel part of it is supposed to be shut down users cannot use excel externally to the program without resorting to ctrl alt del and removing the excel tasks manually.
Not a nice solution !

Any hints for a workaround ?
0 Kudos
Message 7 of 8
(3,289 Views)
if (WorkBookHandle)
CA_DiscardObjHandle(WorkBookHandle);


if (ExcelApplicationHandle)
CA_DiscardObjHandle(ExcelApplicationHandle);

seems to do the trick for now !
0 Kudos
Message 8 of 8
(3,289 Views)