Skip to content

Instantly share code, notes, and snippets.

View rickbrew's full-sized avatar

Rick Brewster rickbrew

  • dotPDN LLC
  • California
View GitHub Profile
@rickbrew
rickbrew / CDynamicCcw.cs
Last active December 5, 2021 00:11
COM Callable Wrapper example using dynamically aggregated wrappers
#nullable enable
using PaintDotNet.ComponentModel;
using PaintDotNet.Runtime;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace PaintDotNet.Interop;
@rickbrew
rickbrew / AggObjectFactory.cs
Last active November 28, 2021 03:33
Dynamic CCW ported to C#
/////////////////////////////////////////////////////////////////////////////////
// paint.net //
// Copyright (C) dotPDN LLC, Rick Brewster, and contributors. //
// All Rights Reserved. //
/////////////////////////////////////////////////////////////////////////////////
#nullable enable
using System;
using System.Runtime.CompilerServices;
@rickbrew
rickbrew / IFxObjectRef.cs
Created November 27, 2021 16:15
First attempt at direct COM interop in C#
[Guid("8A5E0B48-E799-45d2-B714-3A48F48C2615")]
internal unsafe struct IFxObjectRef
: IFxObjectRef.Interface
{
public interface Interface
: IUnknown.Interface
{
unsafe HRESULT GetObject(GCHandle* gcHandle);
}
// Idea 1: SHELLEXECUTEINFOW with nested structs, Windows is flat
public static class SHELLEXECUTEINFOW
{
[StructLayout(..., Pack = 1)]
public struct X86 { ... }
[StructLayout(...)]
public struct X64 { ... }
[StructLayout(...)]
/// <summary>Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements.</summary>
/// <typeparam name="T">The type of object contained as items in the thread-safe collection.</typeparam>
[ComVisible(false)]
public class SynchronizedCollection<T>
: IList<T>,
ICollection<T>,
IEnumerable<T>,
IEnumerable,
IList,
ICollection
@echo off
@rem %1 is the package name, e.g. Microsoft.NETCore.App.Host.win-x64
@rem %2 is the package version, e.g. 5.0.*
@rem %3 is the TargetFramework, e.g. net5.0
@rem %4 is the target folder, e.g. d:\src\pdn\src\lib\, which will not include the version and will have the package name appended to it, e.g. d:\src\pdn\src\lib\Microsoft.NETCore.App.Host.win-x64
rem This uses a dummy project to retrieve the Microsoft.NETCore.App.Host nuget project,
rem which is needed for hostfxr.h, libnethost.lib, and nethost.h.
/////////////////////////////////////////////////////////////////////////////////
// paint.net //
// Copyright (C) dotPDN LLC, Rick Brewster, and contributors. //
// All Rights Reserved. //
/////////////////////////////////////////////////////////////////////////////////
using Microsoft.Toolkit.HighPerformance.Helpers;
using System;
using System.Diagnostics;
using System.Numerics;
#define PLATFORM_ID_INVALID -1
#define PLATFORM_ID_X86 0
#define PLATFORM_ID_X64 1
#define PLATFORM_ID_ARM 2
#define PLATFORM_ID_ARM64 3
// returns S_OK if the OS version check passes, S_FALSE if it doesn't, or a negative value on failure
HRESULT VerifyWindowsVersion(DWORD dwMajor, DWORD dwMinor, DWORD dwBuild, WORD wServicePack) noexcept
{
if (dwMajor < 5)
struct Load32bpp_Scalar_Fn
{
public:
static __forceinline uint32_t invoke(const uint32_t* p)
{
return *p;
}
};
private static unsafe void FillStencilFromPoint<TBitVector2D, TCheckColorFn>(
IRenderer<ColorBgra> sampleSource,
TBitVector2D stencilBuffer,
Point2Int32 startPt,
byte tolerance,
TCheckColorFn checkColorFn,
ICancellationToken cancelToken,
out RectInt32 bounds)
where TBitVector2D : IBitVector2D
where TCheckColorFn : IFunc<ColorBgra, ColorBgra, byte, bool>