NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Using TS_EngineDisplayFileDialog () to obtain a directory path?

I am having trying to implement the 'TS_EngineDisplayFileDialog ()' method to obtain a user specified directory path.

Specifically the two arguents requiring a pointer to pointer to SAFEARRAY. The local help specifies that a specific function must be used to release the SAFEARRAY. Therefore, I declared the two variables:

SAFEARRAY *selPaths = NULL;
SAFEARRAY *absPaths = NULL;

The compiler accepted this without any errors. The resources are then released when no longer needed in the following manner:

if (NULL != selPaths)
CA_SafeArrayDestroy (selPaths);
if (NULL != absPaths)
CA_SafeArrayDestroy (absPaths);

At runtime it's a different story. When TS_EngineDisplayFileDialog is cal
led the following runtime error occurs:

Invalid argument: Expected SAFEARRAY of BSTR.

If these objects get allocated by the call, how can the user preload any info into a nonexistent structure before the call.

I was unable to find any examples of the use of this call. Could someone provide an example of how to use this call, specifically the setup of the two SAFEARRAY arguments?
0 Kudos
Message 1 of 3
(2,718 Views)
To Hurst -
There is some working code in \TestStand\Examples\Java\JavaPathSetup.c(111)

or

here is another example of code:

VARIANT_BOOL gotPath;
std::vector<_bstr_t> pathArr;
TSUTIL::SafeArray selectedPathsArray;
TSUTIL::SafeArray absolutePathsArray;

CComBSTR intialPath = m_TPS;
LPCTSTR szFilter = _T("PAWS Files (*.PAW)|*.PAW|All Files (*.*)|*.*||");
gotPath = m_Engine->DisplayFileDialog(_T(""), _T(""), (LPCTSTR)m_TPS,
&selectedPathsArray, &absolutePathsArray, OpenFile_UseRelativePath, "PAW",
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, vtMissing, NULL, NULL);

if (gotPath)
{
selectedPathsArray.GetVector(pathArr);
m_TPS = (LPCTSTR)pathArr[0];

absolutePathsArray.GetVector(p
athArr);
m_absoluteTPS = (LPCTSTR)pathArr[0];
}


Scott Richardson (NI)
Scott Richardson
0 Kudos
Message 2 of 3
(2,718 Views)
I found an alternate solution to the problem by using the 'TS_EngineSelectFolderDialog ()' method, which works just fine. Strange thing is as I was looking at the source for this function in tsutil.c I noticed that it was virtually identical to what I was doing!
0 Kudos
Message 3 of 3
(2,718 Views)