How to Allocate Global Memory from Within the LCKLast reviewed: August 28, 1995Article ID: Q120467 |
The information in this article applies to:
SUMMARYIt may be necessary to allocate global memory within an FLL. To do this, use the following Windows API functions: GlobalAlloc(), GlobalLock(), GlobalUnlock(), and GlobalFree().
MORE INFORMATIONTo use Windows global memory, follow these steps:
Example CodeThe following program passes a string to the FLL and allocates enough global memory for the string. Fox Code:
SET LIBRARY TO MEMALLOC.FLL =MEMALLOC('THIS IS A TEST')C Code:
#include <windows.h> #include <pro_ext.h> static HANDLE hMem; char FAR *pmem; DWORD before; LPSTR lpstr; void PutLong(long v,int width) { Value val; val.ev_long = v; val.ev_width = width; val.ev_type = 'I'; _PutValue(&val); } void MemAlloc(ParamBlk FAR *parm) { before = GetFreeSpace(0); _PutStr("Total memory avaiable in the Global Heap before memory allocation = "); PutLong(before,10); if(hMem = GlobalAlloc(GMEM_MOVEABLE, parm->p[0].val.ev_length)) { _PutStr("\nAmount of memory allocated ="); PutLong((before-GetFreeSpace(0)),3); lpstr=GlobalLock(hMem); lstrcpy(lpstr,(LPSTR)_HandToPtr(parm->p[0].val.ev_handle)); GlobalUnlock(hMem); GlobalFree(hMem); } _PutStr("\nAmount of memory after hMem is is release = "); PutLong(GetFreeSpace(0),10); } FoxInfo myFoxInfo[]={ {"MEMALLOC",(FPFI)MemAlloc,1,"C"}, }; FoxTable _FoxTable={ (FoxTable FAR*)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo }; |
Additional reference words: FoxWin 2.50 2.50a 2.50b 2.60 2.60a LCK API
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |