static void LoadTaskDialog() { if (!Utility.IsAvailablePlatform()) { throw new PlatformNotSupportedException(); } string systemDirectory = Environment.GetEnvironmentVariable("windir"); foreach (string dir in Directory.EnumerateDirectories(Path.Combine(systemDirectory, "WinSxS"), $"{( IntPtr.Size == 4 ? "x86" : "amd64" )}_microsoft.windows.common-controls_6595b64144ccf1df_6.*")) { hModule = LoadLibraryEx(Path.Combine(dir, "comctl32.dll"), IntPtr.Zero, 0); IntPtr taskDialog = GetProcAddress(hModule, "TaskDialog"); IntPtr taskDialogIndirect = GetProcAddress(hModule, "TaskDialogIndirect"); if (taskDialog == null || taskDialogIndirect == null) { throw new PlatformNotSupportedException(); } #pragma warning disable 0618 taskDialogAction = Marshal.GetDelegateForFunctionPointer(taskDialog, typeof(TaskDialogDelegate)) as TaskDialogDelegate; taskDialogIndirectAction = Marshal.GetDelegateForFunctionPointer(taskDialogIndirect, typeof(TaskDialogIndirectDelegate)) as TaskDialogIndirectDelegate; #pragma warning restore 0618 break; } }
public static int HidP_GetVersion([NativeTypeName("ULONG *")] uint *Version) { int status = (((int)(((0x0) << 28) | (0x11 << 16) | (0)))); * Version = 1; HMODULE module = (HMODULE)NativeLibrary.Load("hid.dll"); if (module == HMODULE.NULL) { return(((int)(((0xC) << 28) | (0x11 << 16) | (8)))); } ReadOnlySpan <sbyte> HidP_GetVersionInternal = new sbyte[] { 0x48, 0x69, 0x64, 0x50, 0x5F, 0x47, 0x65, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x6E, 0x61, 0x6C, 0x00 }; delegate * unmanaged <uint *, int> fnVersionInternal = (delegate * unmanaged <uint *, int>)(GetProcAddress(module, (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(HidP_GetVersionInternal)))); if (fnVersionInternal != null) { status = fnVersionInternal(Version); } else { } return(status); }
public static extern IntPtr GetProcAddress(HMODULE hModule, [NativeTypeName("LPCSTR")] sbyte *lpProcName);
public static extern uint GetModuleFileNameA(HMODULE hModule, [NativeTypeName("LPSTR")] sbyte *lpFilename, [NativeTypeName("DWORD")] uint nSize);
public static extern BOOL FreeLibrary(HMODULE hLibModule);
public static extern BOOL DisableThreadLibraryCalls(HMODULE hLibModule);
public static extern uint SizeofResource(HMODULE hModule, HRSRC hResInfo);
public HRESULT CreateSoftwareAdapter(HMODULE Module, IDXGIAdapter **ppAdapter) { return(((delegate * unmanaged <IDXGIFactory4 *, HMODULE, IDXGIAdapter **, int>)(lpVtbl[11]))((IDXGIFactory4 *)Unsafe.AsPointer(ref this), Module, ppAdapter)); }
/// <summary> /// Runs a specified application and starts the main loop to update its state. This is the entry point for a given application, /// and it should be called as soon as the process is launched, excluding any other additional initialization needed. /// </summary> /// <param name="application">The input application instance to run.</param> /// <returns>The exit code for the application.</returns> public static int Run(Win32Application application) { Win32ApplicationRunner.application = application; HMODULE hInstance = Windows.GetModuleHandleW(null); fixed(char *name = Assembly.GetExecutingAssembly().FullName) fixed(char *windowTitle = application.GetType().ToString()) { // Initialize the window class WNDCLASSEXW windowClassEx = new() { cbSize = (uint)sizeof(WNDCLASSEXW), style = CS.CS_HREDRAW | CS.CS_VREDRAW, lpfnWndProc = &WindowProc, hInstance = hInstance, hCursor = Windows.LoadCursorW(HINSTANCE.NULL, IDC.IDC_ARROW), lpszClassName = (ushort *)name }; // Register the window class _ = Windows.RegisterClassExW(&windowClassEx); Rectangle windowRect = new(0, 0, 1280, 720); // Set the target window size _ = Windows.AdjustWindowRect((RECT *)&windowRect, WS.WS_OVERLAPPEDWINDOW, Windows.FALSE); uint height = (uint)(windowRect.Bottom - windowRect.Top); uint width = (uint)(windowRect.Right - windowRect.Left); // Create the window and store a handle to it hwnd = Windows.CreateWindowExW( 0, windowClassEx.lpszClassName, (ushort *)windowTitle, WS.WS_OVERLAPPEDWINDOW, Windows.CW_USEDEFAULT, Windows.CW_USEDEFAULT, (int)width, (int)height, HWND.NULL, HMENU.NULL, hInstance, (void *)GCHandle.ToIntPtr(GCHandle.Alloc(application)) ); MARGINS margins = default; margins.cxLeftWidth = -1; margins.cxRightWidth = -1; margins.cyTopHeight = -1; margins.cyBottomHeight = -1; _ = Windows.DwmExtendFrameIntoClientArea(hwnd, &margins); } // Initialize the application application.OnInitialize(hwnd); // Display the window _ = Windows.ShowWindow(hwnd, SW.SW_SHOWDEFAULT); MSG msg = default; // Setup the render thread that enables smooth resizing of the window renderThread = new Thread(static args =>
public static extern HRESULT D3D10CreateDeviceAndSwapChain1(IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, uint Flags, D3D10_FEATURE_LEVEL1 HardwareLevel, uint SDKVersion, DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, ID3D10Device1 **ppDevice);
public static extern HRESULT D3D10CreateDevice1(IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, uint Flags, D3D10_FEATURE_LEVEL1 HardwareLevel, uint SDKVersion, ID3D10Device1 **ppDevice);
public static extern int SizeofResource( HMODULE hModule, IntPtr hResInfo);
public static extern IntPtr LoadResource( HMODULE hModule, IntPtr hResInfo);
public static extern IntPtr FindResourceW( HMODULE hModule, IntPtr lpName, IntPtr lpType);
protected static extern int GetModuleBaseName(HANDLE hProcess, HMODULE hModule, StringBuilder lpBaseName, int nSize);
public static extern uint K32GetModuleBaseNameA(HANDLE hProcess, HMODULE hModule, [NativeTypeName("LPSTR")] sbyte *lpBaseName, [NativeTypeName("DWORD")] uint nSize);
static void Main(string[] args) { HMODULE hAppHelp = LoadLibraryW(wszShAppHelpDLL); }
public static extern uint K32GetModuleFileNameExW(HANDLE hProcess, HMODULE hModule, [NativeTypeName("LPWSTR")] ushort *lpFilename, [NativeTypeName("DWORD")] uint nSize);
[DllImport("kernel32.dll", SetLastError = true)] public static extern IntPtr GetProcAddress(HMODULE hModule, string lpModuleName);
public static extern BOOL K32GetModuleInformation(HANDLE hProcess, HMODULE hModule, [NativeTypeName("LPMODULEINFO")] MODULEINFO *lpmodinfo, [NativeTypeName("DWORD")] uint cb);
public static extern BOOL EnumResourceLanguagesExA(HMODULE hModule, [NativeTypeName("LPCSTR")] sbyte *lpType, [NativeTypeName("LPCSTR")] sbyte *lpName, [NativeTypeName("ENUMRESLANGPROCA")] delegate *unmanaged <HMODULE, sbyte *, sbyte *, ushort, nint, BOOL> lpEnumFunc, [NativeTypeName("LONG_PTR")] nint lParam, [NativeTypeName("DWORD")] uint dwFlags, [NativeTypeName("LANGID")] ushort LangId);
public HRESULT LoadCmdFromResource(HMODULE hModule, [NativeTypeName("LPCWSTR")] ushort *pszResourceName, [NativeTypeName("LPCWSTR")] ushort *pszResourceType, [NativeTypeName("WORD")] ushort wLanguage, SPLOADOPTIONS Options) { return(((delegate * unmanaged <ISpRecoGrammar *, HMODULE, ushort *, ushort *, ushort, SPLOADOPTIONS, int>)(lpVtbl[15]))((ISpRecoGrammar *)Unsafe.AsPointer(ref this), hModule, pszResourceName, pszResourceType, wLanguage, Options)); }
public static extern HRSRC FindResourceExW(HMODULE hModule, [NativeTypeName("LPCWSTR")] ushort *lpType, [NativeTypeName("LPCWSTR")] ushort *lpName, [NativeTypeName("WORD")] ushort wLanguage);
public static extern HRESULT D3D11CreateDevice(IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, uint Flags, [NativeTypeName("const D3D_FEATURE_LEVEL *")] D3D_FEATURE_LEVEL *pFeatureLevels, uint FeatureLevels, uint SDKVersion, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext);
public static extern void FreeLibraryAndExitThread(HMODULE hLibModule, [NativeTypeName("DWORD")] uint dwExitCode);
public static extern HRESULT D3D11CreateDeviceAndSwapChain(IDXGIAdapter *pAdapter, D3D_DRIVER_TYPE DriverType, HMODULE Software, uint Flags, [NativeTypeName("const D3D_FEATURE_LEVEL *")] D3D_FEATURE_LEVEL *pFeatureLevels, uint FeatureLevels, uint SDKVersion, [NativeTypeName("const DXGI_SWAP_CHAIN_DESC *")] DXGI_SWAP_CHAIN_DESC *pSwapChainDesc, IDXGISwapChain **ppSwapChain, ID3D11Device **ppDevice, D3D_FEATURE_LEVEL *pFeatureLevel, ID3D11DeviceContext **ppImmediateContext);
public static extern uint GetModuleFileNameW(HMODULE hModule, [NativeTypeName("LPWSTR")] ushort *lpFilename, [NativeTypeName("DWORD")] uint nSize);
public static extern DWORD GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize);
public static extern HGLOBAL LoadResource(HMODULE hModule, HRSRC hResInfo);
public static extern HRESULT D3D10CreateDevice(IDXGIAdapter *pAdapter, D3D10_DRIVER_TYPE DriverType, HMODULE Software, uint Flags, uint SDKVersion, ID3D10Device **ppDevice);