_EdCloseFile( ) API Library Routine Example

The following example opens for editing a single file specified by a parameter, deletes a character, and closes the edit session three times. The first time, the routine calls _EdCloseFile( ) with the "Immediately save" option, the second time with the "Save after dialog box" option, and the third time with the "Open Save As dialog box" option. Each time, the routine shows the return value of _EdCloseFile( ).

Visual FoxPro Code

SET LIBRARY TO EDCLOSE 
= EDCLOSE("x")

C Code

#include <pro_ext.h>

void putLong(long n)
{
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 5;

   _PutValue(&val);
}

FAR Example(ParamBlk FAR *parm)
{
#define pFILENAME ((char FAR *) _HandToPtr(parm->p[0].val.ev_handle))

   WHANDLE wh;
   int retValue;

   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);
   pFILENAME[parm->p[0].val.ev_length] = '\0';

   // Open, delete a character, close "save without asking"
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);

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

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 0); // save without asking
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);

   // Open, delete a character, close "save with asking"
   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 1); // save with asking
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);

   // Open, delete a character, close "save as"
   _HLock(parm->p[0].val.ev_handle);
   wh = _EdOpenFile(pFILENAME, FO_READWRITE);
   _HUnLock(parm->p[0].val.ev_handle);

   _EdSelect(wh, 0, 1);
   _EdDelete(wh);
   retValue = _EdCloseFile(wh, 2); // save as
   _PutStr("\n_EdCloseFile() ="); putLong(retValue);
}

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