[DllImport("getuname.dll", SetLastError=true)]
static extern int GetUName(UInt16 wCharCode, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpbuf);
Declare Function GetUName Lib "getuname.dll" (ByVal wCharCode As UShort, <MarshalAs(UnmanagedType.LPWStr)> ByVal lpbuf As StringBuilder) As Integer
None.
System.Environment.UserName
None.
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.
var sb = new StringBuilder(256);
var len = GetUName('A', sb);
return sb.ToString(0, len);
References:
https://gist.github.com/donnaken15/04c50e77b1bbf41c3afa1fffe5ae2148
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