Skip to content

Instantly share code, notes, and snippets.

View weltkante's full-sized avatar

Tobias Käs weltkante

  • Germany
View GitHub Profile
@weltkante
weltkante / example.cs
Last active March 15, 2022 16:18
Example for Win32 Activat Context to load a regfree COM manifest
[STAThread]
static void Main()
{
ACTCTXW context = new ACTCTXW();
context.cbSize = Marshal.SizeOf<ACTCTXW>();
context.lpSource = "YourManifestFile.manifest";
var handle = Win32.CreateActCtxW(ref context);
if (handle == IntPtr.Zero)
throw new Win32Exception();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
private static extern int MsgWaitForMultipleObjectsEx(int nCount, IntPtr pHandles, int dwMilliseconds, int dwWakeMask, int dwFlags);
private static Action _modalDoEvents;
// WinForms doesn't have a proper modal loop outside ShowDialog
// Sometimes we don't want ShowDialog, eg. for filter bar popups
// There we want the popup to close if we click outside of it, which doesn't work with ShowDialog
//
// The replacement would be message pumping with Application.DoEvents and waiting for new messages
@weltkante
weltkante / ArrayBinder.cs
Created April 5, 2019 09:07
2d array wrapper for WPF datagrid binding
public sealed class ArrayBinder : IBindingList, ITypedList
{
private sealed class ArrayColumn : PropertyDescriptor
{
public ArrayBinder Owner { get; }
public int ColumnIndex { get; }
public ArrayColumn(ArrayBinder owner, int index)
: base($"[{index}]", null)
{
@weltkante
weltkante / program.cs
Created October 30, 2017 10:42
test ref-return and dynamic code generation
using System;
using System.Reflection;
using System.Reflection.Emit;
namespace TestProgram
{
delegate ref int GetRefIntoArrayDelegate(int[] array, int index);
class Program
{
@weltkante
weltkante / script.cs
Created February 3, 2017 14:28
script invocation performance
try
{
var script = CSharpScript.Create<int>("42", globalsType: typeof(Record));
int count = 0;
var start = DateTime.UtcNow;
var now = start;
for (;;)
{
for (int i = 0; i < 100; i++)
@weltkante
weltkante / MainWindow.xaml.cs
Created January 15, 2016 18:39
D3D11Image + DepthBuffer test
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using Microsoft.Wpf.Interop.DirectX;
using SharpDX;
using SharpDX.D3DCompiler;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
private static async Task<CompletionResult> GetCompletionData(ScriptEditorControl parent, CancellationToken cancellationToken = default(CancellationToken))
{
if (!parent.ContainsScript)
return null;
var doc = parent.GetScriptDocument();
var model = await doc.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);
var syntax = await doc.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var text = parent.GetScriptView().CurrentText;