Last active
August 29, 2015 14:21
-
-
Save TLMcode/85138e315552090ab98a to your computer and use it in GitHub Desktop.
Get Character Description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cSharp = | |
( | |
using System; | |
using System.Text; | |
using System.Runtime.InteropServices; | |
public class Win32ResourceReader : IDisposable | |
{ | |
private IntPtr _hModule; | |
public Win32ResourceReader(string filename) | |
{ | |
_hModule = LoadLibraryEx(filename, IntPtr.Zero, LoadLibraryFlags.AsDataFile | LoadLibraryFlags.AsImageResource); | |
if (_hModule == IntPtr.Zero) | |
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); | |
} | |
public string GetDescription(string str) | |
{ | |
uint id = Convert.ToChar(str); | |
var buffer = new StringBuilder(1024); | |
LoadString(_hModule, id, buffer, buffer.Capacity); | |
if (Marshal.GetLastWin32Error() != 0) | |
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error()); | |
return buffer.ToString(); | |
} | |
~Win32ResourceReader() | |
{ | |
Dispose(false); | |
} | |
public void Dispose() | |
{ | |
Dispose(true); | |
GC.SuppressFinalize(this); | |
} | |
public void Dispose(bool disposing) | |
{ | |
if (_hModule != IntPtr.Zero) | |
FreeLibrary(_hModule); | |
_hModule = IntPtr.Zero; | |
} | |
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
static extern int LoadString(IntPtr hInstance, uint uID, StringBuilder lpBuffer, int nBufferMax); | |
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags); | |
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)] | |
static extern bool FreeLibrary(IntPtr hModule); | |
[Flags] | |
enum LoadLibraryFlags : uint | |
{ | |
AsDataFile = 0x00000002, | |
AsImageResource = 0x00000020 | |
} | |
} | |
) | |
Reader := CLR_CreateObject( CLR_CompileC#( cSharp ), "Win32ResourceReader", A_WinDir "\System32\getuname.dll" ) | |
Msgbox % GetDescriptionList( "Char Names123", Reader ) "`n" GetDescriptionList( "ᾯӐɯ♫⓫", Reader ) | |
GetDescriptionList( Str, Obj ) | |
{ | |
For each, Char in ( StrSplit( Str ), DescList := "String: " Str "`n" ) | |
DescList .= Obj.GetDescription( Char ) "`n" | |
return DescList | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment