Billy ONeal
Billy ONeal

Reputation: 106530

How does one read a localized name from the registry?

Consider the following registry export:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WinSock2\Parameters\Protocol_Catalog9\Catalog_Entries\000000000001]
;...
"ProtocolName"="@%SystemRoot%\\System32\\wshtcpip.dll,-60100"

The intention here appears to be for someone to load the DLL in question, and use some form of API retrieve the actual name. But I don't know what that API is :/

I'd like to avoid loading the DLL into my address space (and thus call DLL_PROCESS_ATTACH) if at all possible; can't really trust third party DLLs to be trustworthy.

Upvotes: 2

Views: 539

Answers (2)

Roman Ryltsov
Roman Ryltsov

Reputation: 69632

This is going to help:

HMODULE hModule = LoadLibrary(_T("wshtcpip.dll")); // LoadLibraryEx is even better
TCHAR pszValue[1024] = { 0 };
INT nResult = LoadString(hModule, 60100, pszValue, _countof(pszValue));

LoadString will take care of downloading resource from MUI, if needed. LoadString uses thread locale, which you might want to override prior to the call.

Also: Loading Language Resources on MSDN.

Upvotes: 1

David Heffernan
David Heffernan

Reputation: 612794

RegLoadMUIString will do the necessary for you. Note however, that it was introduced in Vista so won't help if you need to support XP.

If you want to avoid code in the DLL running whilst you extract resources, use LoadLibraryEx passing LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE, or possibly LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE. Once you have done that, you can call LoadString to extract the MUI value.

Upvotes: 5

Related Questions