Skip to content

Instantly share code, notes, and snippets.

View smourier's full-sized avatar

Simon Mourier smourier

View GitHub Profile
@smourier
smourier / ColorDumperSafe
Created June 6, 2020 10:20
Dumps uxtheme immersive colors
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp18
{
public class Program
{
static void Main()
{
GetUserColorPreference(out var pref, false);
#include <windows.ui.composition.interop.h>
#include <ShellScalingAPI.h>
#include <DispatcherQueue.h>
#include <winrt/Windows.System.h>
#include <winrt/Windows.UI.Composition.Desktop.h>
extern "C" IMAGE_DOS_HEADER __ImageBase;
using namespace winrt;
using namespace Windows::UI;
@smourier
smourier / Windows.ModernShare.cpp
Created December 24, 2022 15:45
Shows Windows' "Modern Share" UI in a standard desktop Win32 app.
#include <Windows.h>
#include <ShObjIdl_core.h>
#include <windows.applicationmodel.datatransfer.h> // for the IIDs (ABI namespace)
#include <winrt/windows.applicationmodel.datatransfer.h>
#include <winrt/windows.foundation.collections.h>
#include <winrt/windows.storage.h>
// compile at least with ISO C++20 Standard (/std:c++20)
using namespace winrt;
$Source = @"
using System;
using System.Runtime.InteropServices;
namespace wuapi
{
[ComImport, Guid("ef8208ea-2304-492d-9109-23813b0958e1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IUpdateInstaller4
{
void _VtblGap0_29(); // skip 4 (IDispatch) + 25 IUpdateInstaller4 methods
#include <windows.h>
#include <strsafe.h>
#include <atlbase.h>
#include <mfapi.h>
#include <stdio.h>
#pragma comment(lib, "advapi32")
#pragma comment(lib, "mfreadwrite")
#pragma comment(lib, "mfplat")
#pragma comment(lib, "mfuuid")
private async Task OpenCapturePicker()
{
var picker = new GraphicsCapturePicker();
var handle = new WindowInteropHelper(this).Handle;
var interop = (IInitializeWithWindow)(object)picker;
interop.Initialize(handle);
await picker.PickSingleItemAsync();
}
@smourier
smourier / Program.cs
Last active January 28, 2023 16:09
Open Taskbar's Calendar using UI Automation
using System;
using System.Runtime.InteropServices;
using UIAutomationClient; // add a COM reference to Windows\System32\UIAutomationCore.dll, and set "Embed Interop Types" to false on this reference's properties
namespace ConsoleApp
{
internal class Program
{
private static readonly CUIAutomation8 _ui = new CUIAutomation8();
@smourier
smourier / app.manifest
Created January 31, 2023 18:08
Assembly manifest for reg-free
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="MyAtlFile" type="win32" />
<file name="MyAtlFile.dll">
<comClass
description="Simple Object"
clsid="{a377453e-a407-4533-9c2f-537164c6882e}"
threadingModel="Apartment"
tlbid="{3f4efe00-9913-4fd9-9576-e1c8fc14c724}" />
<typelib
@smourier
smourier / EFIVariableRead.cs
Created March 20, 2023 11:27
Read EFI Variable
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
namespace ConsoleApp2
{
internal class Program
{
// code must be ran as admin
#define _AFXDLL
#include <WinSock2.h> // MFC...
#include <windows.h>
#include <afxwin.h> // CBitmap
#include <atlbase.h>
#include <atlcom.h> // CComPtr
#include <d2d1.h>
#include <d2d1_3.h> // ID2D1DeviceContext5
#include <wincodec.h> // Wic