This is an old revision of the document!
Table of Contents
This is part of Win16 API which allow to create versions of program from one source code to run under OS/2 and Win16. Under OS/2 program can be running under Win-OS/2 if program is Windows NE executable, and with help on Windows Libraries for OS/2, if it is OS/2 NE executable. Here is a WLO to OS/2 API mapping draft
LocalAlloc
Brief
Allocates a block of memory from the local heap of the current data segment.
Syntax
HLOCAL WINAPI LocalAlloc( UINT uFlags, UINT uBytes );
Parameters
uFlags – Allocation attributes. Common flags:
LMEM_FIXED (0x0000) – Allocates fixed memory; the return value is a pointer.
LMEM_MOVEABLE (0x0002) – Allocates movable memory; returns a handle.
LMEM_ZEROINIT (0x0040) – Initializes the memory to zero.
LMEM_DISCARDABLE (0x0F00) – Makes the block discardable (only with LMEM_MOVEABLE).
LMEM_NOCOMPACT (0x0010) – Prevents heap compaction for this allocation.
LMEM_NODISCARD (0x0020) – Prevents discarding of other blocks.
Shorthands: LHND (LMEM_MOVEABLE | LMEM_ZEROINIT), LPTR (LMEM_FIXED | LMEM_ZEROINIT).
uBytes – Number of bytes to allocate. If zero and LMEM_MOVEABLE is set, returns a handle to a discarded object.
Return Value
If successful, returns a handle to the allocated object. For LMEM_FIXED, this handle is actually a pointer.
Returns NULL on failure. Call GetLastError for extended error information.
Notes
For movable blocks, use LocalLock to obtain a pointer before accessing the memory.
The internal lock count of a new block is zero.
Example Code
C Binding
HLOCAL hMem = LocalAlloc(LMEM_MOVEABLE | LMEM_ZEROINIT, 1024); HLOCAL hMem2 = LocalAlloc(LHND, 1024);
MASM Binding
push 0042h ; LMEM_MOVEABLE | LMEM_ZEROINIT push 0400h ; 1024 bytes call LocalAlloc
See also
| Group | Functions |
|---|---|
| Module manager | GETVERSION GETMODULEHANDLE GETMODULEUSAGE GETMODULEFILENAME GETPROCADDRESS MAKEPROCINSTANCE FREEPROCINSTANCE GETINSTANCEDATA CATCH THROW GETCODEHANDLE LOADLIBRARY |
| Memory Manager | GlobalAlloc GlobalCompact GlobalDiscard GlobalFree GlobalLock GlobalReAlloc GlobalSize GlobalUnlock GlobalFlags LocalInit LocalAlloc LocalCompact LocalDiscard LocalFree LocalLock LocalFreeze LocalMelt LocalReAlloc LocalSize LocalUnlock LocalHandleDelta LockData UnlockData LocalFlags |
| Task Scheduler | GetCurrentTask Yield SetPriority |
| Resource Manager | AddFontResource RemoveFontResource LoadBitmap LoadCursor LoadIcon LoadMenu LoadString LoadAccelerators FindResource LoadResource AllocResource LockResource FreeResource AccessResource SizeofResource SetResourceHandler |
| String Translation | AnsiUpper AnsiLower AnsiNext AnsiPrev |
| Atom Manager | InitAtomTable AddAtom DeleteAtom FindAtom GetAtomName |
| Windows Initialization File | GetProfileInt GetProfileString WriteProfileString |
| Debugging | FatalExit |
| File I/O | _lopen _lcreat _llseek _lread _lwrite _lclose OpenFile GetTempFileName GetTempDrive |
| Registry | RegOpenKey RegCreateKey RegCloseKey RegDeleteKey RegSetValue RegQueryValue RegEnumKey |




