Load string from resources |
![]() |
|
|
|
|
|
This method will load a string from the resource table of the DLL or application and place it in the string object, overwriting any previous content there. The string object buffer will be dynamically allocated depending on the resource string length.
In MFC applications, AfxGetResHandle() will be called internally to determine the module instance from which to load the string.
In non-MFC applications, your code should supply a version of the STR_get_stringres function that will return either NULL (for EXE modules) or a DLL instance handle. This function is probably already in your code if you already ran the Add Str Wizard.
The method will return FALSE if the string could not be loaded; in that case, the string object will hold an empty string.
Example: get a string, replace ~ with the newline character, display a messagebox
Str s;
s.LoadString(IDS_MY_MESSAGE);
s.Replace("~", "\n");
MessageBox(NULL, s, NULL, MB_OK);
See also: Windows-specific, FormatRes