Microsoft Opens Up Old Win32 APIs to C# and Rust
visualstudiomagazine.com
visualstudiomagazine.com
Over the years I’ve managed to get pretty good at P/Invokes to the point where I don’t bat an eye when I need to do some interop with native code. That doesn’t mean I don’t sometimes run into a particularly finicky API that requires digging deep into stuff like GC pinning, structure packing, fixed pointers, or other challenges that will grind things to a halt while I debug what’s happening. At least I’ve come to the point where I can look at unexpected API behavior and have a good intuition for what I need to do.
It sucks, a lot.
I’m really glad that there’s finally an official and reusable abstraction to make this simpler in the future.
P/Invoke does not require such a layer - you simply declare enums, structs, and functions from the native API directly in your C# code, and then you can call them.
For those familiar with Python, the Java way is more like writing a Python extension module in C, and the C# way is more like using ctypes (but way faster).
Java has some third party libraries that are basically P/Invoke equivalent; JNA is probably the most used one.
Of course, the downside is that you have to do all the marshaling yourself then. E.g. for strings, you use the appropriate System.String constructor to create one from a raw pointer - it has overloads for null-terminated string pointers as well as pointer + length, and you can specify encoding too. Or, to pass the string to native, you pin it using "fixed" to obtain a pointer.
The article makes it sound like the change is only of interest if you're compiling 32-bit applications.
"Win32 is the 32-bit API" is flat-out wrong.
The article never explicitly said that Win32 is exclusively 32-bit, so it omitted 64-bit.
It's really not, as a standalone statement.
It has a 32 bit part, it is not "32 bit end of sentence".
When I search for "error of omission" specifically, I only get two things. One is an accounting term, completely irrelevant. The other is a dictionary definition of "not including something such as an amount or fact that should be included" which is basically the same as a lie of omission and doesn't fit this situation. They didn't just leave out a fact, they made a statement that was factually wrong.
Edit: You changed your post slightly, is the difference just the word 'intentionally'? Because I wasn't just talking about doing it intentionally.
If Win32 is partially a 32-bit API, what is factually wrong about what they said? For that part to be factually wrong, they would have to say that it's exclusively 32-bit or not at all 32-bit.
Both this situation and the accounting term fit the definition.
It's like saying a ham sandwich "is" bread. Such a statement is flat-out false.
Your example should have been "it's the bread" to match the wording of the article.
Imagine I asked you to go to the store and get whatever as long as you come back with bread and meat. You get a plain baguette and a ham-on-baguette sandwich. When you return, you remove two identically wrapped items of similar size and weight from the grocery bag. I point to one of them and ask "what's that?". You, thinking that it's the plain baguette, answer "it's the bread".
When I discover that it's a ham sandwich, I could be gracious and say that you made an error of omission. After all, it does have bread. And despite believing it to be just bread, you technically didn't say it wasn't also the meat.
Or I could be ungracious and belabor how wrong I think you were.
If you want to be gracious, I would suggest simply not pointing out the mistake. To say I made an error of omission is just not true.
Perhaps MS is encouraging developers to native UI after all.
The "new Microsoft" is still there for sure...
Edit: Here is the actual project if anyone is interested in following along. https://github.com/microsoft/win32metadata/
Specifically when using WinMD? Why?
Or do you mean vs. calling the APIs directly via C code, or vs. using in-language techniques such as P/Invoke?
By the way, .NET is also retiring the ability to use WinMD directly via runtime projection, in favor of code generation: https://github.com/microsoft/CsWinRT
Apples Coca APIs can be queried, and at one point i considered writing a C API generator. My guess it would take a week or two, but at the time I was busy and spending 2 weeks in XCode, wasn't really my idea of good time. Some one should do it.
I love the idea of starting a new modern OS written from the ground up with security and safety in mind sound.
However, it looks like Microsoft took a different direction with WindowsX. Instead, it looks like they have taken a bold leap and hacked out all of the Win32 guts from Windows to make it a Chromebook competitor. And the talk on the town is, further down the line, they will re-add Win32 back in as a virtualised service (i guess kinda like WSL2) so its completely sandboxed from the rest of the OS.
Win32 uses hungarian notation, which is not common these days. The thing was designed for a time in which programming tools had almost no autocompletion and were slightly better than a text editor.