Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetUName (getuname)
 
.
Summary
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:

None.

Alternative Managed API:

System.Environment.UserName

Notes:

None.

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): http://tools.codeplex.com 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;

References:

https://pastebin.com/cLYsakzK

https://gist.github.com/donnaken15/04c50e77b1bbf41c3afa1fffe5ae2148

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>
     <CLSCompliant(False)>
     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%
     Try
         ret = API.Misc.GetUName(codePoint, buff)
     Catch
         Return Nothing
     End Try
     If ret <= 0 Then Return Nothing
     Return buff.ToString

     End Function
End Module

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions