Browse Source

Use widechar variant for win32 pinvokes

pull/11886/head
Trym Lund Flogard 3 years ago
parent
commit
9b66943dd2
  1. 2
      samples/ControlCatalog.NetCore/NativeControls/Win/WinApi.cs
  2. 42
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

2
samples/ControlCatalog.NetCore/NativeControls/Win/WinApi.cs

@ -39,7 +39,7 @@ internal unsafe class WinApi
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true)]
public static extern bool DestroyWindow(IntPtr hwnd); public static extern bool DestroyWindow(IntPtr hwnd);
[DllImport("kernel32.dll")] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryW", ExactSpelling = true)]
public static extern IntPtr LoadLibrary(string lib); public static extern IntPtr LoadLibrary(string lib);

42
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@ -1161,7 +1161,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint); public static extern bool ClientToScreen(IntPtr hWnd, ref POINT lpPoint);
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "CreateWindowExW", ExactSpelling = true)]
public static extern IntPtr CreateWindowEx( public static extern IntPtr CreateWindowEx(
int dwExStyle, int dwExStyle,
uint lpClassName, uint lpClassName,
@ -1215,16 +1215,16 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern int GetMessageTime(); public static extern int GetMessageTime();
[DllImport("kernel32.dll")] [DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetModuleHandleW", ExactSpelling = true)]
public static extern IntPtr GetModuleHandle(string? lpModuleName); public static extern IntPtr GetModuleHandle(string? lpModuleName);
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern int GetSystemMetrics(SystemMetric smIndex); public static extern int GetSystemMetrics(SystemMetric smIndex);
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLongPtrW", ExactSpelling = true)]
public static extern uint GetWindowLongPtr(IntPtr hWnd, int nIndex); public static extern uint GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLong")] [DllImport("user32.dll", SetLastError = true, EntryPoint = "GetWindowLongW", ExactSpelling = true)]
public static extern uint GetWindowLong32b(IntPtr hWnd, int nIndex); public static extern uint GetWindowLong32b(IntPtr hWnd, int nIndex);
public static uint GetWindowLong(IntPtr hWnd, int nIndex) public static uint GetWindowLong(IntPtr hWnd, int nIndex)
@ -1239,10 +1239,10 @@ namespace Avalonia.Win32.Interop
} }
} }
[DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLong")] [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongW", ExactSpelling = true)]
private static extern uint SetWindowLong32b(IntPtr hWnd, int nIndex, uint value); private static extern uint SetWindowLong32b(IntPtr hWnd, int nIndex, uint value);
[DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongPtr")] [DllImport("user32.dll", SetLastError = true, EntryPoint = "SetWindowLongPtrW", ExactSpelling = true)]
private static extern IntPtr SetWindowLong64b(IntPtr hWnd, int nIndex, IntPtr value); private static extern IntPtr SetWindowLong64b(IntPtr hWnd, int nIndex, IntPtr value);
public static uint SetWindowLong(IntPtr hWnd, int nIndex, uint value) public static uint SetWindowLong(IntPtr hWnd, int nIndex, uint value)
@ -1310,7 +1310,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool KillTimer(IntPtr hWnd, IntPtr uIDEvent); public static extern bool KillTimer(IntPtr hWnd, IntPtr uIDEvent);
[DllImport("user32.dll")] [DllImport("user32.dll", EntryPoint = "LoadCursorW", ExactSpelling = true)]
public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName); public static extern IntPtr LoadCursor(IntPtr hInstance, IntPtr lpCursorName);
[DllImport("user32.dll")] [DllImport("user32.dll")]
@ -1319,7 +1319,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool DestroyIcon(IntPtr hIcon); public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("user32.dll")] [DllImport("user32.dll", EntryPoint = "PeekMessageW", ExactSpelling = true)]
public static extern bool PeekMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg); public static extern bool PeekMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax, uint wRemoveMsg);
[DllImport("user32")] [DllImport("user32")]
@ -1334,7 +1334,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool ReleaseCapture(); public static extern bool ReleaseCapture();
[DllImport("user32.dll", SetLastError = true)] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "RegisterWindowMessageW", ExactSpelling = true)]
public static extern uint RegisterWindowMessage(string lpString); public static extern uint RegisterWindowMessage(string lpString);
[DllImport("user32.dll")] [DllImport("user32.dll")]
@ -1415,7 +1415,7 @@ namespace Avalonia.Win32.Interop
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool TranslateMessage(ref MSG lpMsg); public static extern bool TranslateMessage(ref MSG lpMsg);
[DllImport("user32.dll", CharSet = CharSet.Unicode)] [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "UnregisterClassW", ExactSpelling = true)]
public static extern bool UnregisterClass(string lpClassName, IntPtr hInstance); public static extern bool UnregisterClass(string lpClassName, IntPtr hInstance);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetWindowTextW")] [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "SetWindowTextW")]
@ -1439,10 +1439,10 @@ namespace Avalonia.Win32.Interop
[DllImport("shell32", CharSet = CharSet.Auto)] [DllImport("shell32", CharSet = CharSet.Auto)]
public static extern int Shell_NotifyIcon(NIM dwMessage, NOTIFYICONDATA lpData); public static extern int Shell_NotifyIcon(NIM dwMessage, NOTIFYICONDATA lpData);
[DllImport("user32.dll", EntryPoint = "SetClassLongPtr")] [DllImport("user32.dll", EntryPoint = "SetClassLongPtrW", ExactSpelling = true)]
private static extern IntPtr SetClassLong64(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong); private static extern IntPtr SetClassLong64(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong);
[DllImport("user32.dll", EntryPoint = "SetClassLong")] [DllImport("user32.dll", EntryPoint = "SetClassLongW", ExactSpelling = true)]
private static extern IntPtr SetClassLong32(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong); private static extern IntPtr SetClassLong32(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong);
public static IntPtr SetClassLong(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong) public static IntPtr SetClassLong(IntPtr hWnd, ClassLongIndex nIndex, IntPtr dwNewLong)
@ -1463,10 +1463,10 @@ namespace Avalonia.Win32.Interop
return new IntPtr(GetClassLongPtr32(hWnd, nIndex)); return new IntPtr(GetClassLongPtr32(hWnd, nIndex));
} }
[DllImport("user32.dll", EntryPoint = "GetClassLong")] [DllImport("user32.dll", EntryPoint = "GetClassLongW", ExactSpelling = true)]
public static extern uint GetClassLongPtr32(IntPtr hWnd, int nIndex); public static extern uint GetClassLongPtr32(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "GetClassLongPtr")] [DllImport("user32.dll", EntryPoint = "GetClassLongPtrW", ExactSpelling = true)]
public static extern IntPtr GetClassLongPtr64(IntPtr hWnd, int nIndex); public static extern IntPtr GetClassLongPtr64(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetCursor")] [DllImport("user32.dll", EntryPoint = "SetCursor")]
@ -1527,10 +1527,10 @@ namespace Avalonia.Win32.Interop
[DllImport("kernel32.dll", ExactSpelling = true)] [DllImport("kernel32.dll", ExactSpelling = true)]
public static extern IntPtr GlobalFree(IntPtr hMem); public static extern IntPtr GlobalFree(IntPtr hMem);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryW", ExactSpelling = true)]
public static extern IntPtr LoadLibrary(string fileName); public static extern IntPtr LoadLibrary(string fileName);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode, EntryPoint = "LoadLibraryExW", ExactSpelling = true)]
public static extern IntPtr LoadLibraryEx(string fileName, IntPtr hFile, int flags); public static extern IntPtr LoadLibraryEx(string fileName, IntPtr hFile, int flags);
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)] [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Ansi)]
@ -1645,7 +1645,7 @@ namespace Avalonia.Win32.Interop
[DllImport("opengl32.dll", CharSet = CharSet.Ansi)] [DllImport("opengl32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr wglGetProcAddress(string name); public static extern IntPtr wglGetProcAddress(string name);
[DllImport("kernel32.dll", SetLastError = true)] [DllImport("kernel32.dll", SetLastError = true, EntryPoint = "CreateFileMappingW", ExactSpelling = true)]
public static extern IntPtr CreateFileMapping(IntPtr hFile, public static extern IntPtr CreateFileMapping(IntPtr hFile,
IntPtr lpFileMappingAttributes, IntPtr lpFileMappingAttributes,
uint flProtect, uint flProtect,
@ -1668,16 +1668,16 @@ namespace Avalonia.Win32.Interop
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] [DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern void ReleaseStgMedium(ref STGMEDIUM medium); internal static extern void ReleaseStgMedium(ref STGMEDIUM medium);
[DllImport("user32.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "GetClipboardFormatNameW", ExactSpelling = true)]
public static extern int GetClipboardFormatName(int format, StringBuilder lpString, int cchMax); public static extern int GetClipboardFormatName(int format, StringBuilder lpString, int cchMax);
[DllImport("user32.dll", BestFitMapping = false, CharSet = CharSet.Auto, SetLastError = true)] [DllImport("user32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, SetLastError = true, EntryPoint = "RegisterClipboardFormatW", ExactSpelling = true)]
public static extern int RegisterClipboardFormat(string format); public static extern int RegisterClipboardFormat(string format);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)] [DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = true, SetLastError = true)]
public static extern IntPtr GlobalSize(IntPtr hGlobal); public static extern IntPtr GlobalSize(IntPtr hGlobal);
[DllImport("shell32.dll", BestFitMapping = false, CharSet = CharSet.Auto)] [DllImport("shell32.dll", BestFitMapping = false, CharSet = CharSet.Unicode, EntryPoint = "DragQueryFileW", ExactSpelling = true)]
public static extern int DragQueryFile(IntPtr hDrop, int iFile, StringBuilder? lpszFile, int cch); public static extern int DragQueryFile(IntPtr hDrop, int iFile, StringBuilder? lpszFile, int cch);
[DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true, PreserveSig = false)] [DllImport("ole32.dll", CharSet = CharSet.Auto, ExactSpelling = true, PreserveSig = false)]
@ -1893,7 +1893,7 @@ namespace Avalonia.Win32.Interop
[DllImport("imm32.dll")] [DllImport("imm32.dll")]
public static extern bool ImmSetCompositionFont(IntPtr hIMC, ref LOGFONT lf); public static extern bool ImmSetCompositionFont(IntPtr hIMC, ref LOGFONT lf);
[DllImport("imm32.dll", SetLastError = false, CharSet = CharSet.Unicode)] [DllImport("imm32.dll", SetLastError = false, CharSet = CharSet.Unicode, EntryPoint = "ImmGetCompositionStringW", ExactSpelling = true)]
public static extern int ImmGetCompositionString(IntPtr hIMC, GCS dwIndex, [Out, Optional] IntPtr lpBuf, uint dwBufLen); public static extern int ImmGetCompositionString(IntPtr hIMC, GCS dwIndex, [Out, Optional] IntPtr lpBuf, uint dwBufLen);
public static string? ImmGetCompositionString(IntPtr hIMC, GCS dwIndex) public static string? ImmGetCompositionString(IntPtr hIMC, GCS dwIndex)

Loading…
Cancel
Save