Finding and Loading Resources

Before using a resource, an application must load it into memory. The FindResource and FindResourceEx functions find a resource in a module and return a handle to the binary resource data. FindResource locates a resource by type and name. FindResourceEx locates the resource by type, name, and language. Information about FindResource in this topic also applies to FindResourceEx.

The LoadResource function uses the resource handle returned by FindResource to load the resource into memory. After an application loads a resource by using LoadResource, Windows automatically unloads and reloads the resource as memory conditions and application execution require. Thus, an application need not explicitly unload a resource it no longer needs.

An application can use FindResource and LoadResource to find and load any type of resource, but these functions should be used only if the application must access the binary resource data for subsequent function calls. To use a resource immediately, an application should use one of the following resource-specific functions to find and load resources in one call.

Function Action
FormatMessage Loads and formats a message-table entry.
LoadAccelerators Loads an accelerator table.
LoadBitmap Loads a bitmap resource.
LoadCursor Loads a cursor resource.
LoadIcon Loads an icon resource.
LoadImage Loads an icon, cursor, bitmap, or enhanced metafile resource.
LoadMenu Loads a menu resource.
LoadString Loads a string-table entry.

Before terminating, an application should release the memory occupied by accelerator tables, bitmaps, cursors, icons, and menus by using one of the functions in the following table.

Resource Release function
Accelerator table DestroyAcceleratorTable
Bitmap DeleteObject
Cursor DestroyCursor
Icon DestroyIcon
Menu DestroyMenu

When the application terminates, Windows automatically releases the memory occupied by the other types of resources.