用 LoadResource 装入的资源如何释放?
FreeResource 已被作废,用delete 释放有时没问题,有时却有问题。

解决方案 »

  1.   

    FreeResource
    The FreeResource function is obsolete. It is provided to simplify porting of 16-bit Win32-based applications. It is not necessary for Win32-based applications to free resources loaded by using the LoadResource function. The resource obtained by LoadResource is automatically freed when the module is was loaded from is unloaded. However, to save memory and decrease the size of your process's working set, you should release the memory associated with accelerator tables, bitmaps, cursors, icons, and menus by calling the functions in the following table. Resource Release function 
    Accelerator table DestroyAcceleratorTable 
    Bitmap DeleteObject 
    Cursor DestroyCursor 
    Icon DestroyIcon 
    Menu DestroyMenu 
    See Also
    Resources Overview, Resource Functions 
      

  2.   

    msdn上说,现在的Windows系统(大概是95以上)提供的LoadResource这个API,只是取得一个已经载入的资源的内存起始地址而已,并不会分配额外的内存资源。当使用FreeLibrary的时候,才会真正将所有资源释放掉。FreeResource对现在的系统来说,实际上是不做任何处理的。但如果你要兼容Windows3.x,可以用LoadResource和FreeResource配对使用,反正这样写的话,对哪个系统都没错。