_AllocMemo( ) API Library Routine Example

The following example creates new memo field contents.

Visual FoxPro Code

SET LIBRARY TO ALLOMEMO
CREATE TABLE wMemo (memoField M)
APPEND BLANK
= NewMemo(@MemoField, "Hello, World.")
APPEND BLANK
= NewMemo(@MemoField, "Isn't this fun?")

C Code

#include <pro_ext.h>

FAR newMemo(ParamBlk FAR *parm)
{
   Locator FAR *memoFldLoc;
   FCHAN fchMemo;
   int memoLen;
   long loc;

   if ((fchMemo = _MemoChan(-1)) == -1)
   {
      _UserError("_MemoChan() failed");
   }
   memoFldLoc = &parm->p[0].loc;
   memoLen = parm->p[1].val.ev_length;

   if ((loc = _AllocMemo(memoFldLoc, memoLen)) == -1)
   {
      _UserError("_AllocMemo() failed");
   }
   _FSeek(fchMemo, loc, FS_FROMBOF);
   _HLock(parm->p[1].val.ev_handle);
   _FWrite(fchMemo, _HandToPtr(parm->p[1].val.ev_handle), memoLen);
   _HUnLock(parm->p[1].val.ev_handle);
}

FoxInfo myFoxInfo[] = {
   {"NEWMEMO", (FPFI) newMemo, 2, "R,C"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};