PRB: FindResource() in a Service Fails for Localized Resources (197572)
The information in this article applies to:
- Microsoft Win32 Application Programming Interface (API), when used with:
- the operating system: Microsoft Windows NT 4.0
This article was previously published under Q197572 SYMPTOMS
If an executable supports different languages through the use of compiled
resources, FindResource() might return a handle to the wrong resource if it
is called from a service while there is no interactive user.
CAUSE
FindResource() determines which code page to use based on a cache created
when the interactive user logs on to the workstation. An interactive user
is any user who logs on by pressing CTRL+ALT+DEL to access the WinLogon
dialog box. Because a service can run while there is no interactive user,
this cache may not exist. In this event, LoadResource() looks in
Locale.nls, the default National Language Support (NLS) file. This file
always indicates "English (United States)" as the current language, causing
the API to return a handle to the wrong resource.
RESOLUTION
Use FindResourceEx() and pass the default system language identifier as the
wLanguage parameter. This identifier can be retrieved using
GetSystemDefaultLangID(). This API should work correctly from within a
service, even if there is no interactive user.
This solution requires that you change the system's default locale, not
just a user's locale. This is done through the Regional Settings dialog box
of the Control Panel, as follows:
- Select a language other than "English (United States)."
- Select the "Set as system default locale" check box.
- Restart the computer for the changes to take place.
STATUS
Microsoft has confirmed this to be a problem in the Microsoft products
listed at the beginning of this article.
MORE INFORMATION
Other APIs that retrieve resources such as LoadString() may also fail to
retrieve the correct localized resource. In this case, you must use
FindResourceEx(), as explained above, and LoadResource() to retrieve the
resource. You can then format it as necessary.
Modification Type: | Major | Last Reviewed: | 5/6/2004 |
---|
Keywords: | kbKernBase kbprb kbResource kbService KB197572 |
---|
|