_Load( ) API Library Routine Example

The following example converts to uppercase a string argument passed by reference.

Visual FoxPro Code

SET LIBRARY TO LOAD   
x = "abc"
= XUPPER(@x)
? x

C Code

#include <pro_ext.h>

void FAR Upper(ParamBlk FAR *parm)
{
      char FAR *pString;
      Value val;
      int i;
//
//   _Load() and _Store are the functions of interest for pass-by-reference.
//
   _Load(&parm->p[0].loc, &val);
//
//   FoxPro doesn't check the type of pass-by-reference arguments, so we do.
//
  if (val.ev_type != 'C')
   {
      _Error(9); // "Data type mismatch"
   }
  pString = _HandToPtr(val.ev_handle);

   for (i = 0; i < val.ev_length; i++)
   {
      if ('a' <= *pString && *pString <= 'z')
      {
         *pString += ('A' - 'a');
      }
      pString++;
   }
   _Store(&parm->p[0].loc, &val);
   // 
   // We need to free the handle that we created with  _LOAD()
   //
   _FreeHand(val.ev_handle);
}

FoxInfo myFoxInfo[] =
{
   {"XUPPER", (FPFI) Upper, 1, "R"},
};

FoxTable _FoxTable =
{
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};