# microsoft/CsWin32

A source generator to add a user-defined set of Win32 P/Invoke methods and supporting types to a C# project.

Repository: https://github.com/microsoft/CsWin32
Canonical: https://ross.abutalabs.com/products/cswin32
Homepage: https://microsoft.github.io/CsWin32/
Language: C#
License: MIT
License Family: permissive
Last push: 2026-08-26T06:16:53+00:00

## Health v2 (maintenance only)
Score: 96/100 (v2, computed 2026-09-03T02:20:16.233290+00:00)
- activity 99, release rhythm 89, longevity 100
- inputs: {"age_days": 2101, "days_push": 7, "days_rel": 72, "gap_med": 5, "n_releases_24m": 22}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 2518, forks 123 (observed 2026-08-28T04:06:57.790858+00:00)

## What it is
A C# source generator that emits strongly-typed P/Invoke and COM interop bindings for Win32 APIs from .winmd metadata. It generates friendly overloads, SafeHandle support, and XML docs at compile time without shipping extra assemblies.

## Use cases
- call Win32 APIs from C# without hand-writing P/Invoke signatures
- generate type-safe interop bindings for Windows SDK functions
- use COM interfaces from .NET with proper marshaling
- avoid manual DllImport declarations and unsafe code
- get SafeHandle-based resource management for native handles

## When to choose
- you need to call Win32 or COM APIs from a C# project
- you want compile-time generated, strongly-typed interop code
- you prefer no runtime interop assembly dependency

## When to avoid
- you target non-Windows platforms exclusively
- you need cross-platform native interop beyond Win32 metadata
- your project does not use Roslyn source generators

## Facets
- artifact type: library
- maturity: active
- function: developer-tools
- domain: developer-tools, windows, apis
- platform: windows, dotnet, cross-platform
- tags: source-generator, p-invoke, win32, com-interop, csharp, roslyn, code-generation, interop

## Member repositories
- microsoft/CsWin32 (main) score 96

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:06:57.790858+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-30T02:26:07.945057+00:00, confidence not recorded.
  - readme: https://github.com/microsoft/CsWin32 (fetched 2026-08-28T04:06:57.790858+00:00, sha 3acca83def4b)
  - homepage: https://microsoft.github.io/CsWin32/ (fetched 2026-08-29T10:08:14.575844+00:00, sha 32a809a611ad)
- Data as of 2026-08-30T08:39:29.467469+00:00.
