o
odinpkg.dev
packages / library / Win32ExamplesInOdin

Win32ExamplesInOdin

ebe0b01library

This is a repository that contains code from me learning Odin, Win32 api

No license · updated 2 months ago

My Windows Win32 API Odin Examples Repository

What is this

This is a Github repository I manage. I use it to upload examples of things I'm learning when I mess around with the Win32 API.

This means that the examples in here are not the most performant examples. I use them as references and templates for other project and edit those as needed. The main benefit of this repository is working examples to show how to do Win32 related things in Odin.

I come from a python background so the Win32 api was not something I was familar. As such, these examples are kinda scattered in terms of quality. They're like snapshots of different phases of me learning not only Odin, but systems programing as whole.

Originally this started off as a repository to dump my GDI examples in back when i was learning that. But I repurposed this respository to be a more broader Win32 Examples

A lot of the stuff in here I wrote myself, either through C based examples, handmade-hero, etc.

How do the examples work

Unless specificed otherwise, all examples can be run using odin run . For Media Foundations, the mediafoundation.odin file is in the root folder of MediaFoundationExamples. All examples in that folder, will import that file from above as mf

Media Foundation Specifics

The Media Foundations examples uses a medaifoundation.odin file is initially generated by Claude Code. As well as the webcam example in it.

While I tried to use use the mediafoundation.odin from Markersniffen (https://github.com/markersniffen/odin-d3d11-h264-decode), I found it easier to start from scratch, however since I haven't used COM based API before, I needed a base I could start from and reference.

As I continue to explore the media foundation api and the COM API, I'll update the mediafoundation.odin file found here in this repository.

While there is a GDI example with Media Foundation to show that it's possible, the other examples in Media Foundation will be using DX11/DX12 as GDI is CPU/Software based and not as fast as GPU based graphics APIs

Specific Note (MediaFoundationExamples/PlayVideo): This will require you pass a .mp4 (only tested with, but probably any MediaFoundation compatible video) filepath/filename. Look for CreateMediaSource function call from inside the main() proc. That is where you will need to pass the filepath/filename

COM Examples

This holds examples for COM Api related things. While Media Foundation is also COM Api, those are seperate to focus soley on things related to Media Foundation. The COM Examples are more general COM examples, and not focues on any specific topic / hardware.

If enough COM examples that are centered around a specific action (like IO) are gathered, they'll be split off into their own folders.

Resources used while working on this repository

Credit where credit is due, I used a number of different sources and references when I update/work on this repository.

The main resource used for figuring out how Win32 works are:

Win32 API Official Documentation is really the best place to check for argument explinations. A more simplier explination can be found with AI Tools. The Odin bindings for win32 really show how it's implimented in Odin. I recommend just copying the procedure and just slotting in what's needed. You will see almost all procedures in this code use named arguments, that is why. I just copy/paste, slot in where and what needed

For studying C examples; I use AI tools like Copilot and PHIND (shutdown:RIP). I find the odin generation from AI Tools to be incorrect at best and syntatically wrong most of the time. So I have them generate C examples and translate that into Odin myself -- suprisingly easy and worth the effort for learning.

In the past few months, the AI code generation has gotten immensly better at generating Odin code. The above statement is not very true anymore, or at least not to the degree it was before.