Skip to content

Commit

Permalink
Add callconv on win32 apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Feb 2, 2024
1 parent 7baf125 commit 20277b8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
12 changes: 6 additions & 6 deletions src/Snap.Hutao/Snap.Hutao/Win32/AdvApi32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class AdvApi32
{
[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL ConvertSidToStringSidW(PSID Sid, PWSTR* StringSid);

Expand All @@ -26,7 +26,7 @@ public static unsafe BOOL ConvertSidToStringSidW(PSID Sid, out PWSTR StringSid)
}
}

[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL ConvertStringSidToSidW(PCWSTR StringSid, PSID* Sid);

Expand All @@ -41,19 +41,19 @@ public static unsafe BOOL ConvertStringSidToSidW(ReadOnlySpan<char> StringSid, o
}
}

[DllImport("ADVAPI32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL EqualSid(PSID pSid1, PSID pSid2);

[DllImport("ADVAPI32.dll", ExactSpelling = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern WIN32_ERROR RegCloseKey(HKEY hKey);

[DllImport("ADVAPI32.dll", ExactSpelling = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern WIN32_ERROR RegNotifyChangeKeyValue(HKEY hKey, BOOL bWatchSubtree, REG_NOTIFY_FILTER dwNotifyFilter, [AllowNull] HANDLE hEvent, BOOL fAsynchronous);

[DllImport("ADVAPI32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
[DllImport("ADVAPI32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern WIN32_ERROR RegOpenKeyExW(HKEY hKey, [AllowNull] PCWSTR lpSubKey, [AllowNull] uint ulOptions, REG_SAM_FLAGS samDesired, HKEY* phkResult);

Expand Down
8 changes: 4 additions & 4 deletions src/Snap.Hutao/Snap.Hutao/Win32/ApiMsWinNetIsolation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class ApiMsWinNetIsolation
{
[DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)]
[DllImport("api-ms-win-net-isolation-l1-1-0.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows8.0")]
public static unsafe extern uint NetworkIsolationEnumAppContainers(uint Flags, uint* pdwNumPublicAppCs, INET_FIREWALL_APP_CONTAINER** ppPublicAppCs);

Expand All @@ -32,7 +32,7 @@ public static unsafe WIN32_ERROR NetworkIsolationEnumAppContainers(NETISO_FLAG F
}
}

[DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)]
[DllImport("api-ms-win-net-isolation-l1-1-0.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows8.0")]
public static unsafe extern uint NetworkIsolationFreeAppContainers(INET_FIREWALL_APP_CONTAINER* pPublicAppCs);

Expand All @@ -46,7 +46,7 @@ public static unsafe WIN32_ERROR NetworkIsolationFreeAppContainers(ref readonly
}
}

[DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)]
[DllImport("api-ms-win-net-isolation-l1-1-0.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows8.0")]
public static unsafe extern uint NetworkIsolationGetAppContainerConfig(uint* pdwNumPublicAppCs, SID_AND_ATTRIBUTES** appContainerSids);

Expand All @@ -63,7 +63,7 @@ public static unsafe WIN32_ERROR NetworkIsolationGetAppContainerConfig(out uint
}
}

[DllImport("api-ms-win-net-isolation-l1-1-0.dll", ExactSpelling = true)]
[DllImport("api-ms-win-net-isolation-l1-1-0.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows8.0")]
public static unsafe extern uint NetworkIsolationSetAppContainerConfig(uint dwNumPublicAppCs, SID_AND_ATTRIBUTES* appContainerSids);

Expand Down
6 changes: 3 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/Win32/ComCtl32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class ComCtl32
{
[DllImport("COMCTL32.dll", ExactSpelling = true)]
[DllImport("COMCTL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern LRESULT DefSubclassProc(HWND hWnd, uint uMsg, WPARAM wParam, LPARAM lParam);

[DllImport("COMCTL32.dll", ExactSpelling = true)]
[DllImport("COMCTL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL RemoveWindowSubclass(HWND hWnd, [MarshalAs(UnmanagedType.FunctionPtr)] SUBCLASSPROC pfnSubclass, nuint uIdSubclass);

[DllImport("COMCTL32.dll", ExactSpelling = true)]
[DllImport("COMCTL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL SetWindowSubclass(HWND hWnd, [MarshalAs(UnmanagedType.FunctionPtr)] SUBCLASSPROC pfnSubclass, nuint uIdSubclass, nuint dwRefData);
}
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Win32/DwmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class DwmApi
{
[DllImport("dwmapi.dll", ExactSpelling = true)]
[DllImport("dwmapi.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows6.0.6000")]
public static unsafe extern HRESULT DwmSetWindowAttribute(HWND hwnd, uint dwAttribute, void* pvAttribute, uint cbAttribute);

Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Win32/Gdi32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class Gdi32
{
[DllImport("GDI32.dll", ExactSpelling = true)]
[DllImport("GDI32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern int GetDeviceCaps([AllowNull] HDC hdc, int index);

Expand Down
28 changes: 14 additions & 14 deletions src/Snap.Hutao/Snap.Hutao/Win32/Kernel32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class Kernel32
{
[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static extern BOOL AllocConsole();

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL CloseHandle(HANDLE hObject);

[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern HANDLE CreateEventW([AllowNull] SECURITY_ATTRIBUTES* lpEventAttributes, BOOL bManualReset, BOOL bInitialState, [AllowNull] PCWSTR lpName);

Expand All @@ -38,10 +38,10 @@ public static unsafe HANDLE CreateEventW(ref readonly SECURITY_ATTRIBUTES eventA
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static extern BOOL FreeConsole();

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static unsafe extern BOOL GetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE* lpMode);

[SuppressMessage("", "SH002")]
Expand All @@ -54,10 +54,10 @@ public static unsafe BOOL GetConsoleMode(HANDLE hConsoleHandle, out CONSOLE_MODE
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static extern HANDLE GetStdHandle(STD_HANDLE nStdHandle);

[DllImport("KERNEL32.dll", ExactSpelling = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static unsafe extern BOOL K32EnumProcessModules(HANDLE hProcess, HMODULE* lphModule, uint cb, uint* lpcbNeeded);

[DebuggerStepThrough]
Expand All @@ -72,7 +72,7 @@ public static unsafe BOOL K32EnumProcessModules(HANDLE hProcess, Span<HMODULE> h
}
}

[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true)]
public static extern uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMODULE hModule, PWSTR lpBaseName, uint nSize);

[DebuggerStepThrough]
Expand All @@ -84,7 +84,7 @@ public static unsafe uint K32GetModuleBaseNameW(HANDLE hProcess, [AllowNull] HMO
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static unsafe extern BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, MODULEINFO* lpmodinfo, uint cb);

[DebuggerStepThrough]
Expand All @@ -96,7 +96,7 @@ public static unsafe BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModu
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL ReadProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, [MaybeNull] nuint* lpNumberOfBytesRead);

Expand Down Expand Up @@ -125,10 +125,10 @@ public static unsafe BOOL ReadProcessMemory<T>(HANDLE hProcess, void* lpBaseAddr
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static extern BOOL SetConsoleMode(HANDLE hConsoleHandle, CONSOLE_MODE dwMode);

[DllImport("KERNEL32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
public static extern BOOL SetConsoleTitleW(PCWSTR lpConsoleTitle);

[DebuggerStepThrough]
Expand All @@ -140,11 +140,11 @@ public static unsafe BOOL SetConsoleTitleW(ReadOnlySpan<char> consoleTitle)
}
}

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL SetEvent(HANDLE hEvent);

[DllImport("KERNEL32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("KERNEL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static unsafe extern BOOL WriteProcessMemory(HANDLE hProcess, void* lpBaseAddress, void* lpBuffer, nuint nSize, nuint* lpNumberOfBytesWritten);

Expand Down
6 changes: 3 additions & 3 deletions src/Snap.Hutao/Snap.Hutao/Win32/Ole32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class Ole32
{
[DllImport("OLE32.dll", ExactSpelling = true)]
[DllImport("OLE32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern HRESULT CoCreateInstance(Guid* rclsid, [AllowNull] IUnknown pUnkOuter, CLSCTX dwClsContext, Guid* riid, void** ppv);

Expand All @@ -33,11 +33,11 @@ public static unsafe HRESULT CoCreateInstance<T>(ref readonly Guid clsid, [Allow
}
}

[DllImport("OLE32.dll", ExactSpelling = true)]
[DllImport("OLE32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern void CoTaskMemFree([AllowNull] void* pv);

[DllImport("OLE32.dll", ExactSpelling = true)]
[DllImport("OLE32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
public static unsafe extern HRESULT CoWaitForMultipleObjects(uint dwFlags, uint dwTimeout, uint cHandles, HANDLE* pHandles, uint* lpdwindex);

[SuppressMessage("", "SH002")]
Expand Down
2 changes: 1 addition & 1 deletion src/Snap.Hutao/Snap.Hutao/Win32/Shell32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class Shell32
{
[DllImport("SHELL32.dll", ExactSpelling = true)]
[DllImport("SHELL32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows6.0.6000")]
public static unsafe extern HRESULT SHCreateItemFromParsingName(PCWSTR pszPath, [AllowNull] IBindCtx pbc, Guid* riid, void** ppv);

Expand Down
28 changes: 14 additions & 14 deletions src/Snap.Hutao/Snap.Hutao/Win32/User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ namespace Snap.Hutao.Win32;
[SuppressMessage("", "SYSLIB1054")]
internal static class User32
{
[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.1.2600")]
public static extern BOOL AttachThreadInput(uint idAttach, uint idAttachTo, BOOL fAttach);

[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.0")]
public static extern HWND FindWindowExW([AllowNull] HWND hWndParent, [AllowNull] HWND hWndChildAfter, [AllowNull] PCWSTR lpszClass, [AllowNull] PCWSTR lpszWindow);

Expand All @@ -35,23 +35,23 @@ public static unsafe HWND FindWindowExW([AllowNull] HWND hWndParent, [AllowNull]
}
}

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern HDC GetDC([AllowNull] HWND hWnd);

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows10.0.14393")]
public static extern uint GetDpiForWindow(HWND hwnd);

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern HWND GetForegroundWindow();

[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.0")]
public static extern nint GetWindowLongPtrW(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex);

[DllImport("USER32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern BOOL GetWindowPlacement(HWND hWnd, WINDOWPLACEMENT* lpwndpl);

Expand All @@ -64,7 +64,7 @@ public static unsafe BOOL GetWindowPlacement(HWND hWnd, ref WINDOWPLACEMENT wndp
}
}

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern uint GetWindowThreadProcessId(HWND hWnd, [MaybeNull] uint* lpdwProcessId);

Expand All @@ -77,15 +77,15 @@ public static unsafe uint GetWindowThreadProcessId(HWND hWnd, [MaybeNull] out ui
}
}

[DllImport("USER32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows6.0.6000")]
public static extern BOOL RegisterHotKey([AllowNull] HWND hWnd, int id, HOT_KEY_MODIFIERS fsModifiers, uint vk);

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern int ReleaseDC([AllowNull] HWND hWnd, HDC hDC);

[DllImport("USER32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.0")]
public static unsafe extern uint SendInput(uint cInputs, INPUT* pInputs, int cbSize);

Expand All @@ -98,15 +98,15 @@ public static unsafe uint SendInput(ReadOnlySpan<INPUT> inputs, int cbSize)
}
}

[DllImport("USER32.dll", ExactSpelling = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL SetForegroundWindow(HWND hWnd);

[DllImport("USER32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
[SupportedOSPlatform("windows5.0")]
public static extern nint SetWindowLongPtrW(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, nint dwNewLong);

[DllImport("USER32.dll", ExactSpelling = true, SetLastError = true)]
[DllImport("USER32.dll", CallingConvention = CallingConvention.Winapi, ExactSpelling = true)]
[SupportedOSPlatform("windows5.0")]
public static extern BOOL UnregisterHotKey([AllowNull] HWND hWnd, int id);
}

0 comments on commit 20277b8

Please sign in to comment.