_MemCmp( ) API Library Routine
Compares two length byte memory areas.
int _MemCmp(void FAR *ptr1, void FAR *ptr2, unsigned int length)
void FAR *ptr1; /* First point to start compare. */
void FAR *ptr2; /* Second point to start compare. */
unsigned int length; /* How much to compare in bytes. */
Remarks
_MemCmp( ) compares each byte in the two areas, starting with the leftmost byte in each, until two bytes don't match. _MemCmp( ) returns 0 if all bytes in the areas match, a positive number if the first unmatched byte in the first area is greater than the corresponding byte in the second area, or a negative number if the first unmatched byte in the second area is greater than the corresponding byte in the first area.
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 _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
};
See Also
_MemFill( ) API Library Routine | _MemMove( ) API Library Routine | Accessing the Visual FoxPro API