_Execute( ) API Library Routine Example

The following example uses _Execute( ) to execute the passed Visual FoxPro statement.

Visual FoxPro Code

SET LIBRARY TO EXECUTE 
= EXEC("? 'Hello, world.'")
= EXEC("DISPLAY STATUS")

C Code

#include <pro_ext.h>

FAR ExecuteEx(ParamBlk FAR *parm)
{
   char FAR *cmd;

   // Null terminate character string
   if (!_SetHandSize(parm->p[0].val.ev_handle,
      parm->p[0].val.ev_length+1))
   {
      _Error(182); // "Insufficient memory"
   }
   _HLock(parm->p[0].val.ev_handle);
   cmd = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle);
   cmd[parm->p[0].val.ev_length] = '\0';

   _Execute(cmd);

   _HUnLock(parm->p[0].val.ev_handle);
}

FoxInfo myFoxInfo[] = {
   {"EXEC", (FPFI) ExecuteEx, 1, "C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};