FindResourceEx Function

Determines the location of the resource with the specified type, name, and language in the specified module.

Syntax

HRSRC FindResourceEx(      
    HMODULE hModule,     LPCTSTR lpType,     LPCTSTR lpName,     WORD wLanguage );

Parameters

hModule
[in] Handle to the module whose portable executable file or an accompanying MUI file contains the resource. If this parameter is NULL, the function searches the module used to create the current process.
lpType
[in] Specifies the resource type. For more information, see the Remarks section below. For standard resource types, see Resource Types.
lpName
[in] Specifies the name of the resource. For more information, see the Remarks section below.
wLanguage
[in] Specifies the language of the resource. If this parameter is MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), the current language associated with the calling thread is used.

To specify a language other than the current language, use the MAKELANGID macro to create this parameter. For more information, see MAKELANGID.

Return Value

If the function succeeds, the return value is a handle to the specified resource's information block. To obtain a handle to the resource, pass this handle to the LoadResource function.

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

Remarks

If IS_INTRESOURCE(x) is TRUE for x = lpType or lpName, x specifies the integer identifier of the type or name of the given resource. Otherwise, those parameters are long pointers to null-terminated strings. If the first character of the string is a pound sign (#), the remaining characters represent a decimal number that specifies the integer identifier of the resource's name or type. For example, the string "#258" represents the integer identifier 258.

To reduce the amount of memory required for a resource, an application should refer to it by integer identifier instead of by name.

An application can use FindResourceEx to find any type of resource, but this function should be used only if the application must access the binary resource data by making subsequent calls to LoadResource and then to LockResource.

To use a resource immediately, an application should use one of the following resource-specific functions to find the resource and convert the data into a more usable form.

FunctionAction
FormatMessageLoads and formats a message-table entry.
LoadAcceleratorsLoads an accelerator table.
LoadBitmapLoads a bitmap resource.
LoadCursorLoads a cursor resource.
LoadIconLoads an icon resource.
LoadMenuLoads a menu resource.
LoadStringLoads a string-table entry.

For example, an application can use the LoadIcon function to load an icon for display on the screen. However, the application should use FindResourceEx and LoadResource if it is loading the icon to copy its data to another application.

String resources are stored in sections of up to 16 strings per section. The strings in each section are stored as a sequence of counted (not necessarily null-terminated) Unicode strings. The LoadString function will extract the string resource from its corresponding section.

Windows 95/98/Me: The lpType and lpName parameters to FindResourceExW may not be string buffers allocated from the heap. If necessary, copy them to stack buffers and pass the stack buffers.

Windows 95/98/Me: Although FindResourceExW exists on Microsoft Windows 95, Windows 98, and Windows Millennium Edition (Windows Me), it is supported by the Microsoft Layer for Unicode (MSLU) to provide more consistent behavior across all Windows operating systems. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Example

For an example, see Creating a Resource List.

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 ANSI and Unicode versions.

See Also

Tags :


Community Content

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

dmex
C# syntax
[DllImport("kernel32.dll", SetLastError=true)]
public static extern IntPtr FindResourceEx(IntPtr hModule, IntPtr type, IntPtr name, ushort langId);
Tags : c# syntax

Page view tracker