_MemMove( ) API Library Routine
Copies length bytes starting from src to dest.
void _MemMove(void FAR *dest, void FAR *src, unsigned int length)
void FAR *dest; /* Destination. */
void FAR *src; /* Starting position. */
unsigned int length; /* How many bytes to move. */
Remarks
Overlapping moves are performed in the appropriate direction to prevent data corruption.
For more information on how to create an API library and integrate it with Visual FoxPro, see see Accessing the Visual FoxPro API.
Example
The following example uses _MemMove( ) to implement a substring function. From Visual FoxPro, MEMMOVE(s, n1, n2) returns the substring of s starting from position n1 and through position n2.
Visual FoxPro Code
SET LIBRARY TO MEMMOVE
? MEMMOVE("Hello, world.", 8, 10) && returns "wor"
C Code
#include <pro_ext.h>
FAR Example(ParamBlk FAR *parm)
{
int SubstrLen;
MHANDLE bufferHandle;
char FAR *FirstDest;
SubstrLen = parm->p[2].val.ev_long - parm->p[1].val.ev_long + 1;
if ((bufferHandle = _AllocHand(SubstrLen + 1)) == 0)
{
_Error(182); // "Insufficient memory"
}
_HLock(bufferHandle);
_HLock(parm->p[0].val.ev_handle);
FirstDest = (char FAR *) _HandToPtr(parm->p[0].val.ev_handle) +
parm->p[1].val.ev_long - 1;
_MemMove(_HandToPtr(bufferHandle), FirstDest, SubstrLen);
((char FAR *) _HandToPtr(bufferHandle))[SubstrLen] = '\0';
_RetChar(_HandToPtr(bufferHandle));
_HUnLock(bufferHandle);
_HUnLock(parm->p[0].val.ev_handle);
}
FoxInfo myFoxInfo[] = {
{"MEMMOVE", (FPFI) Example, 3, "C,I,I"},
};
FoxTable _FoxTable = {
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
See Also
_MemCmp( ) API Library Routine | _MemFill( ) API Library Routine | Accessing the Visual FoxPro API