LoadResource

The LoadResource function loads the specified resource into global memory.

HGLOBAL LoadResource(
  HMODULE hModule, // resource-module handle
  HRSRC hResInfo   // resource handle
);
 

Parameters

hModule
Handle to the module whose executable file contains the resource. If hModule is NULL, the system loads the resource from the module that was used to create the current process.
hResInfo
Handle to the resource to be loaded. This handle must be created by using the FindResource or FindResourceEx function.

Return Values

If the function succeeds, the return value is a handle to the data associated with the resource.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The return type of LoadResource is HGLOBAL for backward compatibility, not because the function returns a handle to a global memory block. Do not pass this handle to the GlobalLock or GlobalFree function. To obtain a pointer to the resource data, call the LockResource function.

When you are finished using an accelerator table, bitmap, cursor, icon, or menu, you can release its associated memory by calling one of the functions in the following table.

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

The system automatically deletes these resources when the process that created them terminates, however, calling the appropriate function saves memory and decreases the size of the process's working set.

Windows CE: The hModule parameter must be non-NULL.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winbase.h.
  Import Library: Use kernel32.lib.

See Also

Resources Overview, Resource Functions, FindResource, FindResourceEx, LoadLibrary, LoadModule, LockResource