_MemCmp( ) API Library Routine Example

The following example uses _MemCmp( ) to compare two character parameters up to the length of the first unmatched byte.

Visual FoxPro Code

SET LIBRARY TO MEMCMP  
? MEMCMP("Hello, world.", "Hello, world.")  && returns 0
? MEMCMP("Hello, world.", "Hello, wurld.")  && returns non-0

C Code

#include <pro_ext.h>

#define min(a, b) ((a) < (b) ? (a) : (b))

FAR Example(ParamBlk FAR *parm)
{
   int LenToCmp, RetValue;

   LenToCmp = min(parm->p[0].val.ev_length, parm->p[1].val.ev_length);

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

   RetValue = _MemCmp(_HandToPtr(parm->p[0].val.ev_handle),
      _HandToPtr(parm->p[1].val.ev_handle), LenToCmp);

   _RetInt(RetValue, 10); // does return control here

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

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