各位大虾:如果再一个函数里面申请内存{GlobalAlloc();lp = GlobaLock().......
,return lp },
   我想问一下,我把内存锁定的指针lp给返回出来了,那么我怎么在这个函数外面进行释放我在函数里面申请的内存呢?????

解决方案 »

  1.   

    HGLOBAL GlobalFree(
      HGLOBAL hMem   // handle to global memory object
    );
      

  2.   

    GlobalFreeThe GlobalFree function frees the specified global memory object and invalidates its handle.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.
    HGLOBAL GlobalFree(
      HGLOBAL hMem
    );Parameters
    hMem 
    [in] Handle to the global memory object. This handle is returned by either the GlobalAlloc or GlobalReAlloc function. 
    Return Values
    If the function succeeds, the return value is NULL.If the function fails, the return value is equal to a handle to the global memory object. To get extended error information, call GetLastError.Res
    If the process examines or modifies the memory after it has been freed, heap corruption may occur or an access violation exception (EXCEPTION_ACCESS_VIOLATION) may be generated.If the hgblMem parameter is NULL, GlobalFree fails and the system generates an access violation exception.The GlobalFree function will free a locked memory object. A locked memory object has a lock count greater than zero. The GlobalLock function locks a global memory object and increments the lock count by one. The GlobalUnlock function unlocks it and decrements the lock count by one. To get the lock count of a global memory object, use the GlobalFlags function.If an application is running under a debug version of the system, GlobalFree will issue a message that tells you that a locked object is being freed. If you are debugging the application, GlobalFree will enter a breakpoint just before freeing a locked object. This allows you to verify the intended behavior, then continue execution.
      

  3.   

    我想问一下,我在函数外面得到是那个内存区域的指针,不能用GlobalFree(handle)来释放
    因为globalFree的参数是句柄,我的问题,也可以这样说,怎么把我的那块内存的指针,转换为
    那块内存的句柄,这样我就能用GlobalFree来释放了!!求救各位大虾!!!
      

  4.   

    在函数里面申请的内存句柄是函数里面的变量,拿出来肯定不好用。 如果把句柄返回用GlobalFree
    肯定是要的,谢谢!,可是我想返回指针,各位大虾有没有什么好方法!!?????
      

  5.   

    拷,受不了。 GlobalFree( (HANDLE)lp ) 即可