12-12-2019 01:01 PM
Runtime error window:
NON-FATAL RUN-TIME ERROR: "c:\...\CVI\Includes\excel_datafile_stuff.c", line 1004, col 13, thread id 9752: Function FileSelectPopup: (return value == -180 [0xffffff4c]). The dialog cannot be displayed in a thread whose concurrency model is multithread apartment (MTA)
Code function call:
char currentFilename[MAX_PATHNAME_LEN] = {"C:\\Users\\Public\\Documents"};
char newFilename[MAX_PATHNAME_LEN];
...
FileSelectPopup (currentFilename, "*.xlsx", "*.xlsx;*.xls;*.txt;*.csv", "Select Data file",
VAL_SELECT_BUTTON, 0, 1, 1, 1, newFilename);
Windows10, CVI 2019
{userint.h}
#define MAX_PATHNAME_LEN 260 /* includes nul byte */
This code worked ok in CVI 2012 - CVI 2017
01-24-2020 10:33 AM
Added this to "main"
int main (int argc, char *argv[])
{
if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */
if ((panelHandle = LoadPanel (0, "QMxxx.uir", PANEL)) < 0)
return -1;
if ((plotPanelHandle = LoadPanel (0, "QMxxx.uir", PLOT_PANEL)) < 0)
return -1;
panelHandle1 = NewPanel (1, "Excel Datafile Control", VAL_AUTO_CENTER, VAL_AUTO_CENTER, 180, 380); // setup save panel
... {other main declares...}
(new code!)
unsigned int threadStyle = COINIT_APARTMENTTHREADED;
//Valid values are COINIT_MULTITHREADED and COINIT_APARTMENTTHREADED.
CA_InitActiveXThreadStyleForCurrentThread (0, threadStyle);
(end of new code insert)
// Excell file control panel creation
excel_file_control_panel();
// end of excel file control panel creation
DisplayPanel (panelHandle);
RunUserInterface ();
... (to the end of main)
Forcing the thread style to "COINIT_APARTMENTTHREADED" appears to solve the RT error.
don't know why or what other issues will be broken from this change.
ChipB.
01-29-2020 12:48 PM
FileSelectPopup must be run in a single threaded environment due to Windows limitation. If you are not running any multithreaded code, you will be fine. If your code is multithreaded, you must spin off a new thread and run FileSelectPopup in that thread (where that thread is in itself single threaded) and then return the filename to the main thread.