Calling Method

<< Click to Display Table of Contents >>

Navigation:  TerraPhoto User Guide > Programming Interface > MDL Public Functions >

Calling Method

Calling Method

The functions can be called with mdlCExpression_ getValue(). The code example below illustrates the method:

void    Example( void)

{

   int     Ret ;

   if (TphotoCall( &Ret, "FnPhotoCount()") > 0)

       mdlOutput_printf( MSG_PROMPT, “%d references attached”, Ret) ;

}

 

/*-------------------------------------------------------------------

   Call a function in TerraPhoto.

   Set *Ret to be the return value.

   Return 1 if successful.

   Return 0 if could not load TPHOTO.

   Return -1 if failed.

*/

int     TphotoCall( int *Ret, const char *Expr)

{

   CExprValue    Val ;

   CExprResult   Res ;

   int           Ok ;

   if (!LoadApp( “TPHOTO”))

       return (0) ;

   Ok = mdlCExpression_getValue( &Val, &Res, Expr, VISIBILITY_CALCULATOR);

   if (Ok != SUCCESS)

       return (-1) ;

   if (Ret)

       *Ret = (int) Val.val.valLong ;

   return (1) ;

}

 

/*-------------------------------------------------------------------

   Load MDL application with Name (such as “TPHOTO”).

   Return 1 if successful.

   Return 0 if application not found.

*/

int    LoadApp( char *Name)

{

   void    *Ptr ;

   int     Ok ;

   //  Is application already loaded?

   Ptr = mdlSystem_findMdlDesc( Name) ;

   if (Ptr)                               return (1) ;

   // Not loaded, attempt loading

   Ok = mdlSystem_loadMdlProgram( Name, NULL, "") ;

   if (Ok == SUCCESS)                     return (1) ;

   return (0) ;

}