LoadResource Function

Loads the specified resource into global memory.

Syntax

HGLOBAL LoadResource(      
    HMODULE hModule,     HRSRC hResInfo );

Parameters

hModule
[in] 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] Handle to the resource to be loaded. This handle is returned by the FindResource or FindResourceEx function.

Return Value

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.

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
FormatMessageLoads and formats a message-table entryNo action needed
LoadAcceleratorsLoads an accelerator tableDestroyAcceleratorTable
LoadBitmapLoads a bitmap resourceDeleteObject
LoadCursorLoads a cursor resourceDestroyCursor
LoadIconLoads an icon resourceDestroyIcon
LoadMenuLoads a menu resourceDestroyMenu
LoadStringLoads 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.

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.

Example

For an example see Updating Resources.

Function Information

Minimum DLL Versionkernel32.dll
HeaderDeclared in Winbase.h, include Windows.h
Import libraryKernel32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as Unicode version.

See Also

Tags :


Community Content

dmex
vb.net syntax
<DllImport("kernel32.dll", SetLastError:=True)> _
Public Shared Function LoadResource(ByVal hModule As IntPtr, ByVal lpResourceInfo As IntPtr) As IntPtr
End Function
Tags : vb.net syntax

dmex
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
internal static extern IntPtr LoadResource(IntPtr hModule, IntPtr lpResourceInfo);
Tags : c# syntax

Page view tracker