Revisiting Programming Windows by Petzold using Rust.
I started my Windows programming adventure in 1992 using Microsoft’s C compiler version 5, the Windows SDK and Charles Petzold’s wonderful book Programming Windows.
Flash forward to 2022 and Microsoft has released a Rust crate that wraps the Windows API.
For not very practical purposes I decided to re-write some of Petzold’s source code originally written in C using the Rust for Windows crate.
From the first chapter of Petzold’s book, 5th edition:
The Windows equivalent to the “hello, world” program has exactly the same components as the character-mode version. It has an include statement, a program entry point, a function call, and a return statement. Here’s the program:
Let’s duplicate the ‘HelloMsg’ program above using Rust. I am assuming that you have the Rust toolchain installed on Windows and know how to open a command prompt and have a text editor such as VS Code at your disposal.
From a command prompt enter the following command:
Change to the hello_msg directory, edit the Cargo.toml file and insert the following at the end:
Now replace the contents of main.rs with the code below:
Enter cargo run at the command prompt and voilà!
For me there is something satisfying about the continuity of code from thirty years ago being used in a modern language such as Rust.
Stay tune as I work my way through Petzold’s book and having fun using Rust my favorite programming language.