I am trying to access a VI by C/C++ almost identical to the reference example that can be found on this site for Visual Basic. However, somehow, I am unable to succeed to use the ActiveX Call() function. The program always crashes, whatever I try. Because the Visual Basic version works without any problems, I hope someone can point me the error in the code.
Thanks!
#include "stdafx.h"
#import "LabVIEW.tlb"
#define VIPATH "D:\\Program Files\\National Instruments\\LabVIEW 7.0\\examples\\apps\\freqresp.llb\\Frequency Response.vi"
using namespace LabVIEW;
int _tmain(int argc, _TCHAR* argv[])
{
// Initialization
HRESULT he = NULL;
he = CoInitialize(NULL);
// Create instance of
labview application engine
_ApplicationPtr pLV;
he = pLV.CreateInstance("LabVIEW.Application");
// Create instance of virtual instrument
VirtualInstrumentPtr pVI;
he = pVI.CreateInstance("LabVIEW.VirtualInstrument"); /* ?not? mandatory */
// Get reference to a VI at location VIPATH
_bstr_t viPath(VIPATH);
_bstr_t password("");
VARIANT_BOOL resvForCall = FALSE;
long options = 0;
pVI = pLV->GetVIReference(viPath,password,resvForCall,options);
// Show front panel
pVI->FPWinOpen = TRUE;
// Call the referenced VI as subVI
_variant_t paramNames[5] = {"Amplitude", "Number of Steps", "Low Frequency", "High Frequency", "Response Graph"};
_variant_t paramVals[5] = {}; /* VT_EMPTY */
/* Fill ParamVals with values from VI */
for (int i = 0; i < 5; ++i) paramVals[i] = pVI->GetControlValue(paramNames[i].bstrVal);
/* Call VI -> !!! CRASH !!! 😞 */
pVI->Call(paramNames,paramVals);
// Release references and close application
pLV->AutomaticC
lose = TRUE;
pVI.Release();
pLV.Release();
CoUninitialize();
return 0;
}