Skip to content

Instantly share code, notes, and snippets.

View mmozeiko's full-sized avatar

Mārtiņš Možeiko mmozeiko

View GitHub Profile
@mmozeiko
mmozeiko / dxgl.c
Last active March 1, 2023 10:53
WGL_NV_DX_interop2 example
#define COBJMACROS
#define INITGUID
#include <intrin.h>
#include <windows.h>
#include <d3d11.h>
#include <gl/GL.h>
#include "glext.h" // https://www.opengl.org/registry/api/GL/glext.h
#include "wglext.h" // https://www.opengl.org/registry/api/GL/wglext.h
@mmozeiko
mmozeiko / overlapped_named_pipe.cpp
Last active March 15, 2024 13:06
Example how to use read-only named pipes with single client in non-blocking way on single thread
#include <windows.h>
#include <stdio.h>
#include <assert.h> // for potential error handling, change to real errors in your code
int main()
{
HANDLE pipe = CreateNamedPipeW(
L"\\\\.\\pipe\\lolcat",
PIPE_ACCESS_INBOUND | FILE_FLAG_FIRST_PIPE_INSTANCE | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT | PIPE_REJECT_REMOTE_CLIENTS,
@mmozeiko
mmozeiko / build.bat
Last active May 25, 2023 05:24
build.bat with caching (for VS2019)
@echo off
setlocal EnableDelayedExpansion
set BUILD_CACHE=%~dp0\_build_cache.cmd
if exist "!BUILD_CACHE!" (
rem cache file exists, so call it to set env variables very fast
call "!BUILD_CACHE!"
) else (
if not exist "%VS2019INSTALLDIR%\VC\Auxiliary\Build\vcvarsall.bat" (
@mmozeiko
mmozeiko / crt.cpp
Created January 16, 2017 01:33
MSVC CRT startup
#include <windows.h>
extern "C"
{
#pragma section(".CRT$XIA",long,read)
#pragma section(".CRT$XIZ",long,read)
#pragma section(".CRT$XCA",long,read)
#pragma section(".CRT$XCZ",long,read)
#pragma section(".CRT$XPA",long,read)
#pragma section(".CRT$XPZ",long,read)
@mmozeiko
mmozeiko / test.c
Last active November 19, 2023 13:25
gtk widget from x11 window
// gcc test.c `pkg-config --cflags --libs gtk+-3.0 gdk-3.0` -lX11 && ./a.out
#include <X11/Xlib.h>
#include <unistd.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
static void my_gtk_realize(GtkWidget* widget, gpointer user)
@mmozeiko
mmozeiko / hook.c
Last active March 14, 2024 05:33
reads process stdout + stderr and prints it out as it becomes available
// compile this to hook.dll
// for example, with MSVC: cl.exe /LD /MT /O2 hook.c /Fehook.dll
#include <windows.h>
// get this from https://github.com/kubo/plthook
#include "plthook_win32.c"
static plthook_t* hook;
@mmozeiko
mmozeiko / floor.c
Last active March 17, 2024 08:25
floor function for floats with SSE1 or SSE2
// floor function for floats with SSE1 or SSE2
#include <emmintrin.h>
#include <smmintrin.h>
#ifdef _MSC_VER
#include <intrin.h>
#else
#define __rdtsc() __builtin_ia32_rdtsc()
#endif
@mmozeiko
mmozeiko / dwrite.cpp
Created July 25, 2018 17:36
DirectWrite without D2D
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <dwrite.h>
#include <intrin.h>
#pragma comment (lib, "gdi32.lib")
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "dwrite.lib")
#define CHECK(x) do { if (!(x)) __debugbreak(); } while (0)
@mmozeiko
mmozeiko / go_aeshash.h
Created November 14, 2018 07:34
Go's AES-NI based hash
#include <stddef.h>
#include <stdint.h>
#include <intrin.h>
// see aeshashbody in https://github.com/golang/go/blob/master/src/runtime/asm_amd64.s
// this is initialized on process startup with random from system
static __declspec(align(16)) uint8_t aeskeysched[128];
static __declspec(align(16)) const uint8_t masks[16][16] =