GlobalLock函数

GlobalLock函数
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。

 
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值