Last active
April 4, 2025 08:11
-
-
Save itn3000/96803cb76b511764de73aca5e7e3d632 to your computer and use it in GitHub Desktop.
CsWin32 Resource API Helper
This file contains hidden or 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
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); | |
} | |
} | |
} |
This file contains hidden or 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
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