LoadResource function

Retrieves a handle that can be used to obtain a pointer to the first byte of the specified resource in memory.

Syntax


HGLOBAL WINAPI LoadResource(
  _In_opt_  HMODULE hModule,
  _In_      HRSRC hResInfo
);

Parameters

hModule [in, optional]

Type: HMODULE

A 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 [in]

Type: HRSRC

A handle to the resource to be loaded. This handle is returned by the FindResource or FindResourceEx function.

Return value

Type: HGLOBAL

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 first byte of the resource data, call the LockResource function; to obtain the size of the resource, call SizeofResource.

To use a resource immediately, an application should use the following resource-specific functions to find and load the resource in one call.

FunctionActionTo remove resource
FormatMessage Loads and formats a message-table entryNo action needed
LoadAccelerators Loads an accelerator table DestroyAcceleratorTable
LoadBitmap Loads a bitmap resource DeleteObject
LoadCursor Loads a cursor resource DestroyCursor
LoadIcon Loads an icon resource DestroyIcon
LoadMenu Loads a menu resource DestroyMenu
LoadString Loads a string resourceNo action needed

 

For example, an application can use the LoadIcon function to load an icon for display on the screen, followed by DestroyIcon when done.

Examples

For an example see Updating Resources.

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

See also

Reference
FindResource
FindResourceEx
LockResource
Conceptual
Resources
Other Resources
LoadLibrary
LoadModule

 

 

Community Additions

ADD
Show:
© 2014 Microsoft