GetUName (getuname)
Last changed: -

An undocumented function used by charmap.exe to obtain (localized) name of a Unicode character.

C# Signature:

[DllImport("getuname.dll", SetLastError=true)]
static extern int GetUName(UInt16 wCharCode, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpbuf);

VB Signature:

Declare Function GetUName Lib "getuname.dll" (ByVal wCharCode As UShort, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpbuf As StringBuilder) As Integer

User-Defined Types:


Alternative Managed API:




Tips & Tricks:

If you want to obtain (localized) names of Unicode characters, instead calling this function you can also load strings from the same place the function loads them. On Windows 7 it means from file \System32\{Culture}\getuname.dll.mui. ({Culture} is name of culture you want to obtain localized resources for e.g. en-US). An advantage of this approach is that you can choose culture without need to switch current Windows language (Windows Ultimate edition only).

Managed wrapper (shown below) of this function will be part of next version of the Đ-Tools library (1.5.4): as well as sample implementation of the other approach.

Sample C# Code:

public static string charactername = new string('*', 255); // stored at root class for other uses

GetUName('A', charactername);
charactername = charactername.Substring(0, charactername.IndexOf('*') - 1);
//return charactername;


Sample VB Code:

Module UnicodeNative
     ''' <summary>Undocumented Win API function for getting localized character names</summary>
     ''' <param name="wCharCode">Character code (code-point)</param>
     ''' <param name="lpBuf">When function returns returns return value</param>
     ''' <returns>Number of characters returned</returns>
     Private Declare Function GetUName Lib "getuname.dll" (ByVal wCharCode As UShort, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpbuf As System.Text.StringBuilder) As Integer

     ''' <summary>Gets localized name uf Unicode character</summary>
     ''' <param name="codePoint">Code point to get localizaed name of</param>
     ''' <returns>
     ''' Localized name of character represented by <paramref name="codePoint"/>. The name is localized to current system locale, not to current thread UI culture.
     ''' Returns null if <paramref name="codePoint"/> is not supported by Windows function for getting character names (i.e. <paramref name="codePoint"/> is greater than <see cref="UInt16.MaxValue"/>) or if name cannot be obtained or windows function call failed.
     ''' </returns>
     ''' <exception cref="ArgumentOutOfRangeException"><paramref name="codePoint"/> is greater than 0x10FFFF</exception>
     ''' <remarks>
     ''' <para>This function is not CLS-Compliant. CLS-compliant overload exists.</para>
     ''' <para>This function relies on undocumented Windows API <c>GetUName</c>. It is possible that this API will be changed or removed in future version of Windows and this function will become slow and start returning nullls for all calls. It can also possibly carsh your application or system. Use on own risk.</para>
     ''' </remarks>
     Public Function GetCharacterName(codePoint As UInteger) As String
     If codePoint > &H10FFFFUI Then Throw New ArgumentOutOfRangeException("codePoint")
     If codePoint > UShort.MaxValue Then Return Nothing

     Dim buff As New StringBuilder(1024)

     Dim ret%
         ret = API.Misc.GetUName(codePoint, buff)
         Return Nothing
     End Try
     If ret <= 0 Then Return Nothing
     Return buff.ToString

     End Function
End Module