windows_programming_notes.nbk: Home | Index | Next Page: FindResourceEx | Previous Page: FILETIME


 FindResource

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

To specify a language, use the FindResourceEx function.

Syntax

    HRSRC FindResource(
        HMODULE hModule,
        LPCTSTR lpName,
        LPCTSTR lpType
    );

Parameters

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 = lpName or lpType, x specifies the integer identifier of the name or type 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 FindResource to find any type of resource, but this function should be used only if the application must access the binary resource data when making subsequent calls to LockResource.

To use a resource immediately, an application should use one of the following resource-specific functions to find and load the 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. 
    LoadMenu Loads a menu resource. 
    LoadString Loads 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 FindResource 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 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 FindResourceW 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 FindResourceW 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 .

Function Information


windows_programming_notes.nbk: Home | Index | Next Page: FindResourceEx | Previous Page: FILETIME


Notebook exported on Monday, 7 July 2008, 18:56:50 PM Eastern Daylight Time