加上WINDOWSX.H 试试
GlobalAllocPtr is a macro defined in WINDOWSX.H that allocates the memory, locks the handle, and returns a pointer to the allocated memory. To free the memory, use GlobalFreePtr. There is no need to retain memory handles or lock and unlock memory blocks.
What makes this possible is the GlobalHandle function, which takes a pointer and returns the handle to it. GlobalHandle removes the need for saving and tracking handles, resulting in incredible savings in time, memory, and complexity.
Other convenient memory macros in WINDOWSX.H are:
GlobalPtrHandle
GlobalLockPtr
GlobalUnlockPtr
GlobalReAllocPtr
If these macros were C functions, they would be prototyped as follows:
void FAR * GlobalAllocPtr(UINT flags, DWORD size) ;
// Allocates and locks a block of size bytes with the
// flags set.
BOOL GlobalFreePtr(void FAR* lp) ;
// Unlocks and frees the block pointer by lp;
// returns a non-zero on success.
void FAR * GlobalReAllocPtr(void FAR* lp, DWORD size, UINT flags) ;
// Reallocates the block pointed to by lp to size bytes with
// the flags set.
// The return value is the pointer to the reallocated block.
HGLOBAL GlobalPtrHandle(void FAR* lp) ;
// Gets global handle pointed to by lp from FAR pointer.
BOOL GlobalLockPtr(void FAR* lp) ;
// Locks the block lp points to.
// If successful, returns a non-zero value.
BOOL GlobalUnlockPtr(void FAR* lp) ;
// Unlocks the block lp points to.
// If successful, returns a non-zero value.
For the curious, here are the definitions of GlobalAllocPtr and GlobalFreePtr: