10-04-2007 05:31 PM
I have an application that written as client and server. The server is a regular DLL that is written in C++ in which the function "TestSpreadSheet()" has been exposed for client to use. The client is TestStand application in which there is an action to call function "TestSpreadSheet() in DLL".
Here is my function in DLL:
TestSpreadSheet()
{
CNiExcelApplication ExcelApp(false, CNiComInitialize::Multithreaded ); // CNiComInitialize::Apartment mode seems not working if called from TestStand
CNiExcelWorkbook WorkBook = ExcelApp.OpenWorkbook("Limit.xsl");
CNiExcelWorksheet WorkSheet = WorkBook.GetWorksheet("Sheet1");
CNiExcelCellRange Row1 = WorkSheet.GetRange("1:1");
Num = Row1.GetColumnWidth(); //Crash!!!
...
}
When the function is called by the action in TestStand the server crashed at “Row1.GetColumnWidth();”.
Measurement Studio has an example at C:\Program Files\National Instruments\MeasurementStudioVS2003\VCNET\Examples\Office\ExcellReport. The major difference between ExcellReport and my DLL code is that CNiExcellApplication is defined as mode of CNiComInitialize::Apartment and there is no problem using CNiExcelCellRange::GetColumnWidth() in this case. However it causes crash in if CNiExcellApplication is instanced as CNiComInitialize::Multithreaded mode.
10-05-2007 03:39 PM
10-05-2007 04:10 PM
Andy,
Thank you for the reply.
Yes, in my function I instance the CNiExcelApplication as "Multithreaded". The reason is that this function will be called from TestStand and it doesn't work if I instance CNiExcelApplication as "Apartment".
TestStand doesn't provide convenient way to read .xls file so that I have a couple of functions in DLL to retrieve the data from .xls and pass the data back to TestStand.
In my DLL all CNiExcelApplication, CNiExcelWorkbook, CNiExcelWorksheet and CNiExcelCellRange member functions I used work fine in "Multithreaded" mode. Only one function causes crash which is "CNiExcelCellRange::GetColumnWidth()". This function works fine in "Apartment" mode.
Kathy
10-09-2007 01:22 PM