Find a function in the specified file and compile and link it as needed.
Function FindFunction( LPCSTR lpcszFunctionName, LPCSTR lpcszFileName = NULL, BOOL bCompileDependents = false, BOOL bSuppressPromptBox = false, BOOL bCheckFileChange = false, int nOverloadIndex = 0, const FunctionPointer& funcRef = NULL )
Returns a valid pointer to the found function on success and an invalid function pointer on failure.
EX1
// This code demonstrates how FindFunction may be used // to make a function call by means of a function pointer void AddColumns(Worksheet& wks, int nn) { if( wks ) { for( int ii = 0; ii < nn; ii++ ) { wks.AddCol(); } } } typedef void (*FUNCTYPE)(Worksheet& wks, int nn); void myFunction() { string strPath; strPath.Format("%sOriginC\\OriginLab\\test.c", GetAppPath(TRUE)); Function fn = Project.FindFunction("AddColumns", strPath); FUNCTYPE pfn = fn; // Can also be done on one line: //FUNCTYPE pfn = Project.FindFunction("AddColumns", strPath); if( pfn ) { Worksheet wks; wks.Create(); pfn(wks, 5); } }
EX2
// following example can be found in OriginEvents.c typedef bool (*FUNC_OCEVENTS)(DataRange &dr, int nWinType); static void OnWksSelectionChange(DataRange &dr) { // can use relative path from OriginC subpath, also, file extention .c is assumed Function fn = Project.FindFunction("OnSelChange", "OriginLab\\GlobalEvents"); FUNC_OCEVENTS pfn = fn; if(pfn) pfn(dr, EXIST_WKS); }
EX3
// This is a complete example that shows how to call the import_file // function defined in OriginLab's FileImport.c file. #include <Origin.h> typedef int (*ImportFileFuncPtr)(LPCSTR strPageName, int nIndexLayer, LPCSTR lpcszDataFile, LPCSTR lpcszFilterName); void import_file_to_active_layer() { // This example will import Origin's simple group.dat file. string strDataFile; strDataFile.Format("%sSamples\\Graphing\\group.dat", GetAppPath(TRUE)); // Get full path of the file containing the function definition. string strPath; strPath.Format("%sOriginC\\OriginLab\\FileImport.c", GetAppPath(TRUE)); // Find the function in the specified file and compile and link it // and its dependencies. ImportFileFuncPtr pfn = Project.FindFunction("import_file", strPath, true); if( pfn ) { Worksheet wks = Project.ActiveLayer(); if( wks ) { WorksheetPage pg = wks.GetPage(); pfn(pg.GetName(), wks.GetIndex(), strDataFile, "ASCII.oif"); } } }
origin.h