Skip to content

Instantly share code, notes, and snippets.

@itn3000
Last active April 4, 2025 08:11
Show Gist options
  • Save itn3000/96803cb76b511764de73aca5e7e3d632 to your computer and use it in GitHub Desktop.
Save itn3000/96803cb76b511764de73aca5e7e3d632 to your computer and use it in GitHub Desktop.
CsWin32 Resource API Helper
using Windows.Win32;
using Windows.Win32.Foundation;
static class IntResourceHelper
{
public static string GetResourceIdOrName(PWSTR lpName)
{
unsafe
{
var addr = new IntPtr(lpName.Value);
if(IsIntResource(addr))
{
return addr.ToString();
}
else
{
return new string(lpName.AsSpan());
}
}
}
public static string GetResourceIdOrName(PCWSTR lpName)
{
unsafe
{
var addr = new IntPtr(lpName.Value);
if (IsIntResource(addr))
{
return addr.ToString();
}
else
{
return new string(lpName.AsSpan());
}
}
}
// Alternative for IS_INTRESOURCE
public static bool IsIntResource(IntPtr ptr)
{
return IsIntResource((UIntPtr)ptr);
}
// Alternative for IS_INTRESOURCE
public static bool IsIntResource(UIntPtr ptr)
{
return (((UIntPtr.MaxValue) << 16) & ptr) == 0;
}
// Alternative for MAKEINTRESOURCE
public static PWSTR MakeIntPwstrResource(IntPtr ptr)
{
return new PWSTR(ptr);
}
// Alternative for MAKEINTRESOURCE
public static PCWSTR MakeIntPcwstrResource(IntPtr ptr)
{
unsafe
{
return new PCWSTR((char*)ptr);
}
}
}
BeginUpdateResource
EndUpdateResource
FindResourceEx
LoadLibrary
HRSRC
GetLocaleInfoEx
LoadResource
LOCALE_NAME_INVARIANT
LOCALE_NAME_SYSTEM_DEFAULT
LOCALE_RETURN_NUMBER
LOCALE_SNAME
LOCALE_ILANGUAGE
LockResource
SizeofResource
EnumResourceNames
EnumResourceTypes
RT_STRING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment