/// <summary>
/// Get a string resource given a resource Id
/// </summary>
/// <param name="resourceId">The resource Id</param>
/// <returns>The string resource corresponding to the given resource Id. Returns null if the resource id
/// is invalid or the string cannot be retrieved for any other reason.</returns>
public static string GetStringResource(string resourceId)
{
string[] parts;
string library;
int index;
if (string.IsNullOrEmpty(resourceId))
{
return(string.Empty);
}
// Known folder "Recent" has a malformed resource id
// for its tooltip. This causes the resource id to
// parse into 3 parts instead of 2 parts if we don't fix.
resourceId = resourceId.Replace("shell32,dll", "shell32.dll");
parts = resourceId.Split(new char[] { ',' });
library = parts[0];
library = library.Replace(@"@", string.Empty);
library = Environment.ExpandEnvironmentVariables(library);
IntPtr handle = CoreNativeMethods.LoadLibrary(library);
parts[1] = parts[1].Replace("-", string.Empty);
index = int.Parse(parts[1], CultureInfo.InvariantCulture);
StringBuilder stringValue = new StringBuilder(255);
int retval = CoreNativeMethods.LoadString(handle, index, stringValue, 255);
return(retval != 0 ? stringValue.ToString() : null);
}