现在的位置: 首页 > 综合 > 正文

GlobalLock函数

2013年10月05日 ⁄ 综合 ⁄ 共 1991字 ⁄ 字号 评论关闭

The GlobalLock function locks a global memory object and returns a pointer to the first byte of the object's memory block. GlobalLock

函数将一个全局内存对象锁定,并返回该块内存首字节指针

Note The global functions are slower than other memory management functions and do not provide as many features. Therefore, new applications should use the heap functions. However, the global functions are still used with DDE and the clipboard functions.

注意全局内存管理函数比其他内存管理函数慢,并且不能提供更多的特征。因此,新应用程序应该使用堆函数,同时考虑到兼容性,全局函数仍然用于DDE和剪切板函数。

 LPVOID GlobalLock( HGLOBAL hMem // handle to global memory object

);

Parameters

hMem [in] Handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function. 参数: hMem [输入参数]全局内存对象句柄。

该句柄由函数GlobalAlloc或GlobalReAlloc返回。

Return Values If the function succeeds, the return value is a pointer to the first byte of the memory block. If the function fails, the return value is NULL. To get extended error information, call GetLastError.

 返回值如果函数执行成功,返回值就是指向内存对象首字节指针,否则返回NULL。调用GetLastError可以得到更多错误信息.

Remarks The internal data structures for each memory object include a lock count that is initially zero. For movable memory objects, GlobalLock increments the count by one, and the GlobalUnlock function decrements the count by one. For each call that a process makes to GlobalLock for an object, it must eventually call GlobalUnlock. Locked memory will not be moved or discarded, unless the memory object is reallocated by using the GlobalReAlloc function. The memory block of a locked memory object remains locked until its lock count is decremented to zero, at which time it can be moved or discarded.

备注内存对象的内部数据结构域如锁记数将会初始化为0。对于可移动内存对象,GlobalLock会将计数器加1,而GlobalUnlock函数将计数器减1。对于GlobalLock的每一次调用,都必须相应的调用一次GlobalUnlock函数。除非使用GlobalReAlloc函数对内存对象进行重新分配,否则被锁定的内存空间不能够被移动或释放。直到计数器为0时被锁定的内存块才会可以被移动或者释放。

 Memory objects allocated with GMEM_FIXED always have a lock count of zero. For these objects, the value of the returned pointer is equal to the value of the specified handle. 以GMEM_FIXED

属性开辟的内存块空间的计数器始终为0,对于这样的对象,函数的返回指针值即为该句柄值。

If the specified memory block has been discarded or if the memory block has a zero-byte size, this function returns NULL. 如果指定的内存块已经被释放或者大小为0字节,该函数将返回NULL。

 Discarded objects always have a lock count of zero.

释放后的对象的计数器为0

抱歉!评论已关闭.