Skip to content

Latest commit

 

History

History
 
 

zwin32

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

zwin32 - Zig bindings for Win32 API

Can be used on Windows and Linux. Contains partial bindings for:

  • Win32 API
  • Direct3D 12
  • Direct3D 11
  • DXGI
  • DirectML
  • Direct2D
  • XAudio2
  • Wincodec (WIC)
  • WASAPI
  • Media Foundation
  • DirectWrite

Getting started

Copy zwin32 folder to a libs subdirectory of the root of your project.

Then in your build.zig add:

const std = @import("std");
const zwin32 = @import("libs/zwin32/build.zig");

pub fn build(b: *std.Build) void {
    ...
    const optimize = b.standardOptimizeOption(.{});
    const target = b.standardTargetOptions(.{});

    const zwin32_pkg = zwin32.package(b, target, optimize, .{});

    zwin32_pkg.link(exe, .{ .d3d12 = true, .xaudio2 = true, .directml = true });
}

Now in your code you may import and use zwin32:

const zwin32 = @import("zwin32");
const w32 = zwin32.w32;
const dwrite = zwin32.dwrite;
const dxgi = zwin32.dxgi;
const d3d12 = zwin32.d3d12;
const d3d12d = zwin32.d3d12d;
const dml = zwin32.directml;

pub fn main() !void {
    ...
    const winclass = w32.WNDCLASSEXA{
        .style = 0,
        .lpfnWndProc = processWindowMessage,
        .cbClsExtra = 0,
        .cbWndExtra = 0,
        .hInstance = @ptrCast(w32.HINSTANCE, w32.GetModuleHandleA(null)),
        .hIcon = null,
        .hCursor = w32.LoadCursorA(null, @intToPtr(w32.LPCSTR, 32512)),
        .hbrBackground = null,
        .lpszMenuName = null,
        .lpszClassName = name,
        .hIconSm = null,
    };
    _ = w32.RegisterClassExA(&winclass);
}