Share via


_Execute( ) API Library Routine

Compiles and executes the null-terminated statement you specify in stmt.

int _Execute(char FAR *stmt)
char FAR *stmt;            /* Statement to execute. */

Remarks

The stmt parameter can be any command or function that can be executed from the Command window. When execution of the statement is complete, control normally returns to the C statement immediately following the call to _Execute( ). Exceptions include executing code that performs a Visual FoxPro CANCEL or QUIT command.

_Execute( ) returns the Visual FoxPro internal error number for any error that occurs during execution of the statement, or 0 if no error occurs.

Note   Do not call _Execute( ) from an event handler.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

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
};

See Also

_Evaluate( ) API Library Routine | CANCEL Command | QUIT Command | Accessing the Visual FoxPro API