Skip to content

Instantly share code, notes, and snippets.

@AlexRasch
Last active July 4, 2022 14:38
Show Gist options
  • Save AlexRasch/fd9f84371c0ba29b132d8da028ad4122 to your computer and use it in GitHub Desktop.
Save AlexRasch/fd9f84371c0ba29b132d8da028ad4122 to your computer and use it in GitHub Desktop.
MessageBoxA
using System.Runtime.InteropServices; // For Pinvoke & Win Api
namespace ConsoleApp1
{
internal class Program
{
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
public static extern int MessageBoxA(IntPtr hWnd, String text, String caption, uint type);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int MessageBoxW(IntPtr hWnd, String text, String caption, uint type);
static void Main(string[] args)
{
// Does not display correct
MessageBoxA(IntPtr.Zero, "фыфыфывы", "фывыфыв", 0);
// Displays the chars correct notice the W and CharSet difference
MessageBoxW(IntPtr.Zero, "фыфыфывы", "фывыфыв", 0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment