public string Get(uint srid) { // Limit input to range of known safe resource string ID's in compstui.dll if (srid < IDS_CPSUI_STRID_FIRST || srid > IDS_CPSUI_STRID_LAST) { if (srid == IDS_NULL) { return(null); } throw new ArgumentOutOfRangeException("srid", srid, string.Empty); } SafeModuleHandle handle = EnsureModuleHandle(); if (handle != null && !handle.IsInvalid) { StringBuilder resString = new StringBuilder(MaxSRLength, MaxSRLength); int charCount = UnsafeNativeMethods.LoadStringW(handle, srid, resString, resString.Capacity); resString.Length = Math.Max(0, Math.Min(charCount, resString.Length)); // The resource string have ampersands in them for menu acclerators. They need to be removed for (int i = 0; i < resString.Length - 1; i++) { if (resString[i] == '&') { char next = resString[i + 1]; if (char.IsLetterOrDigit(next) || char.IsPunctuation(next)) { resString.Remove(i, 1); } } } return(resString.ToString()); } return(null); }
public static extern int LoadStringW(SafeModuleHandle hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax);