Export (0) Print
Expand All
14 out of 33 rated this helpful - Rate this topic

LoadString function

Loads a string resource from the executable file associated with a specified module, copies the string into a buffer, and appends a terminating null character.

Syntax


int WINAPI LoadString(
  _In_opt_  HINSTANCE hInstance,
  _In_      UINT uID,
  _Out_     LPTSTR lpBuffer,
  _In_      int nBufferMax
);

Parameters

hInstance [in, optional]

Type: HINSTANCE

A handle to an instance of the module whose executable file contains the string resource. To get the handle to the application itself, call the GetModuleHandle function with NULL.

uID [in]

Type: UINT

The identifier of the string to be loaded.

lpBuffer [out]

Type: LPTSTR

The buffer is to receive the string.

nBufferMax [in]

Type: int

The size of the buffer, in characters. The string is truncated and null-terminated if it is longer than the number of characters specified. If this parameter is 0, then lpBuffer receives a read-only pointer to the resource itself.

Return value

Type: int

If the function succeeds, the return value is the number of characters copied into the buffer, not including the terminating null character, or zero if the string resource does not exist. To get extended error information, call GetLastError.

Remarks

Security Remarks

Using this function incorrectly can compromise the security of your application. Incorrect use includes specifying the wrong size in the nBufferMax parameter. For example, if lpBuffer points to a buffer szBuffer which is declared as TCHAR szBuffer[100], then sizeof(szBuffer) gives the size of the buffer in bytes, which could lead to a buffer overflow for the Unicode version of the function. Buffer overflow situations are the cause of many security problems in applications. In this case, using sizeof(szBuffer)/sizeof(TCHAR) or sizeof(szBuffer)/sizeof(szBuffer[0]) would give the proper size of the buffer.

Examples

For an example, see Creating a Child Window

Requirements

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

LoadStringW (Unicode) and LoadStringA (ANSI)

See also

Reference
LoadAccelerators
LoadCursor
LoadIcon
LoadMenu
LoadMenuIndirect
Conceptual
Strings
Other Resources
FormatMessage
LoadBitmap

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.