win32 with rust: DirectX 9 starter

I’ve created a few simple Win32 apps in previous posts to compare C++ and Rust. Even with unsafe Rust via the windows crate, Win32 API programming feels more accessible to me.

This time, I decided to pivot and add COM objects to our Win32 app. My previous examples were based on GDI, hence adding some Direct3D sounds like a good next step. The issue is that it’s been a while since I last used it, so I chose the familiar Direct3D 9 API. Yes, it’s old, but the windows crate supports it in windows::Win32::Graphics::Direct3D9. The module is manageable, and there are plenty of C++ examples. I found [this tutorial] (http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-1) and decided to replicate it in Rust.

Read more

win32 with rust: winsafe

We previously created a Rust version of the classic C++ “Your First Windows Program” using the windows crate in the post win32 with rust: simple windows. While the final result worked well, all win32 API calls in that example are unsafe. There is nothing wrong with that, but are there any safe alternatives?

Thankfully, the winsafe crate offers a safe abstraction over win32 API calls. It also provides higher-level, idiomatic, and opinioned abstractions for working with win32 subsystems.

Read more