Partager via


_HandToPtr( ) API Library Routine

Translates a memory handle to a FAR (32-bit) pointer, which points to the memory allocated to this handle.

void FAR * _HandToPtr(MHANDLE hand)
MHANDLE hand;            /* Memory handle. */

Remarks

Visual FoxPro may reorganize memory any time control is passed to it or to another routine outside of the current module.

**Note   **_HandToPtr( ) doesn't cause memory reorganization. The pointer returned by _HandToPtr( ) may become invalid any time control is passed back to Visual FoxPro, unless the MHANDLE is locked. Don't keep pointers to unlocked memory handles across an external function call, unless it is documented that the call doesn't cause memory reorganization.

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.

Visual FoxPro Code

SET LIBRARY TO HANDTOPT
= HANDTOPTR("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[] = {
   {"HANDTOPTR", (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 | _HLock( ) API Library Routine | _HUnLock( ) | _MemAvail( ) API Library Routine | _SetHandSize( ) API Library Routine | Accessing the Visual FoxPro API