什么时候用
globallock()
不太明白,直接左边等于右边不就得了么,为什么要锁定

解决方案 »

  1.   

    因为windows的很多内存块都是可移动的,如果你不锁定它,有可能被系统整理内存时移到别处去。
      

  2.   

    主要是用于锁住全局内存,然后对其进行修改,以免在修改过程中,内存块被系统交换或移动。你写过clipboard的代码的话你就明白了
      

  3.   

    GlobalLock函数,MSDN是这样解释的:
    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. 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. If the specified memory block has been discarded or if the memory block has a zero-byte size, this function returns NULL. Discarded objects always have a lock count of zero.