1.3.2 Calling X-Functions in Origin CX-Function, Execution in Origin C
X-Function, Set Parameters in Origin C
Origin comes with many X-Functions for handling a variety of tasks. X-Functions can be called from both LabTalk and Origin C. This Section will show you how to call X-Functions from Origin C using Origin C's XFBase classXFBase Class. This mechanism also can be used in calling one X-Function in another X-Function.
The XFBase class is declared in the XFBase.h header file located in the <Origin exe folder>\OriginC\system\ folder. The XFBase.h header file is not included in the Origin.h header file and must be included separately in any Origin C file that uses the XFBase class.
#include <XFBase.h>
Calling the impFile X-Function From Origin C
The following Origin C code defines a general function for importing files into Origin. The function takes two arguments: a data file name and an import filter file name. The function first creates an instance of the XFBase class, constructed with the name of the X-Function to be called. In this case, the X-Function name is impFile. It then sets the X-Function arguments using the SetArg method, and finally calls the X-Function using the Evaluate method.
bool call_impFile_XF(LPCSTR lpcszDataFile, LPCSTR lpcszFilterFile)
{
string strDataFile = lpcszDataFile;
string strFilterFile = lpcszFilterFile;
// Create an instance of XFBase using the X-Function name.
XFBase xf("impFile");
if (!xf)
return false;
// Set the 'fname' argument.
if (!xf.SetArg("fname", strDataFile))
return false;
// Set the 'filtername' argument.
if (!xf.SetArg("filtername", strFilterFile))
return false;
// Call XFBase's 'Evaluate' method to execute the X-Function
if (!xf.Evaluate())
return false;
return true;
}
The following Origin C code shows how to call our call_impFile_XF function defined above. We will call it to import an image file.
// Lets import the Car bitmap located in Origin's Samples folder.
string strImageFile = GetAppPath(TRUE) +
"Samples\\Image Processing and Analysis\\Car.bmp";
// Lets import the bitmap using the Image import filter.
string strFilterFile = GetAppPath(TRUE) + "Filters\\Image.oif";
// Let's call our general function that will call the impFile X-Function.
call_impFile_XF(strImageFile, strFilterFile);
Related Link
Calling X-Functions from Script
|