I'm attempting to get the xlslib library (http://sourceforge.net/projects/xlslib/) to work in my Windows MFC program (VC 2010). The Excel file generated can be somewhat large and I need to be able to write multiple Excel files without closing the dialog, which has caused some problems.
The root class is called "workbook". I initially declared:
workbook xls;
in the function that handles Excel export, but that blew up the stack. xls got too large.
Next attempt I declared m_xls in the class definition for my dialog, but I can't figure out how to clear m_xls between calls and if you run the Excel export more than once when the dialog is open, the data from the first run ends up in the second, the third run gets data from the 1st and 2nd, etc.
I tried clearing the data from the first run at the end of the export function. I looked at what was done in the deconstructor for the class to delete the data from the main data storage vector. The workbook class is very complex with many sub-classes and no matter when I try the program becomes very unstable after the first run through the Excel code (after clearing the data) and I get an assert in a thread pool function when I quit the program and a number of first chance exceptions in the output window.
Lastly I declared a workbook pointer in the class and then dynamically allocated a workbook with:
m_pxls = new workbook;
at the start of the function. At the end I deallocate with delete:
delete m_pxls;
This blows up the program with the following error message:
HEAP[Program.exe]: Heap block at 06329360 modified at 0632950A past requested size of 1a2
Windows has triggered a breakpoint in Program.exe.
This may be due to a corruption of the heap, which indicates a bug in Program.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while Program.exe has focus.
The output window may have more diagnostic information.
It looks like all that was allocated was the basic class with no data in it and all data added by the functions in xlslib went way outside the bounds of the memory allocated. Maybe I'm misunderstanding something, but don't the deconstructors for workbook and all its subclasses get called when the memory is deallocated?
I need to figure out how to do one of two things here:
1) Figure out how to re-initialize the statically declared m_xls in the class definition on further calls to the Excel code. OR
2) Figure out what is going on with the allocation and deallocation and get new/delete to work properly.
I've been programming for some time, but this gets into a nuance of memory management I've never run into before. I know I'm probably missing something obvious about new/delete I should know...
Thanks in advance