Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TLMcode/85138e315552090ab98a to your computer and use it in GitHub Desktop.
Save TLMcode/85138e315552090ab98a to your computer and use it in GitHub Desktop.
Get Character Description
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