Share via


_HLock( ) API Library Routine

Locks a memory handle to prevent it from moving if Visual FoxPro requires memory reorganization.

void _HLock(MHANDLE hand)
MHANDLE hand;            /* Memory handle. */

Remarks

_HLock( ) doesn't cause memory reorganization. Unlock the MHANDLE as soon as the lock has served its purpose.

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 displays its character parameter on the screen. It uses _HandToPtr( ) to translate the memory handle of the API parameter to a C pointer. Because Visual FoxPro may decide to reorganize memory during the call to _PutStr( ), to insure proper execution, the example locks the memory handle with _HLock( ). The example also calls _HUnLock( ) at the end, because the performance of Visual FoxPro can be adversely affected by locked memory handles.

Visual FoxPro Code

SET LIBRARY TO HLOCK 
= HLOCK("Hello, world.") && displays "Hello, world" on screen

C Code

#include <pro_ext.h>

void NullTerminate(Value FAR *cVal)
{
   if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1)) 
   {
      _Error(182); // "Insufficient memory"
   }
   ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0';
}

FAR Example(ParamBlk FAR *parm)
{
   NullTerminate(&parm->p[0].val);
   _HLock(parm->p[0].val.ev_handle);
   _PutStr(_HandToPtr(parm->p[0].val.ev_handle));
   _HUnLock(parm->p[0].val.ev_handle);
}

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

See Also

_AllocHand( ) API Library Routine | _FreeHand( ) API Library Routine | _GetHandSize( ) API Library Routine | _HandToPtr( ) API Library Routine | _HUnLock( ) API Library Routine | _MemAvail( ) API Library Routine | _SetHandSize( ) API Library Routine | Accessing the Visual FoxPro API