5 ms·
A Rust `bool` is not a WinAPI `BOOL`, for one thing they have different sizes. A wrapper function could translate between the two... but even that's not univers
by ChrisSD 6y ago
A Rust `bool` is not a WinAPI `BOOL`, for one thing they have different sizes. A wrapper function could translate between the two... but even that's not universally possible. Depending on the API, `BOOL` can sometimes have three or more values (e.g. -1, 0 or 1). So whatever happens you need a safe wrapper around the function call that understands what `BOOL` means in this specific context.
Incidentally, there is no reason why the metadata can't be improved with more information that can be used to create safer wrappers. The winmd format isn't restricted to only that which can be represented in C's type system.
- DaiPlusPlus 6y agowinmd is limited to the .NET type system - an improvement over C, but still insufficiently expressive enough imo. I suppose you could hack it by adding new Attributes...
- ChrisSD 6y agoSee: https://github.com/microsoft/win32metadata#winmd-emitter-overview https://github.com/microsoft/win32metadata#winmd-emitter-ove... It seems at least one of their hacks is not valid in the CLR, so that bridge has been crossed. Plus they do make use of attributes.
- oaiey 6y agoI think this C# intermediate is just a tooling thing. The winmd format is already extended beyond .NET IMHO. And I think, they have thought about that before they startet :)
- DaiPlusPlus 6y agoSome things aren’t expressable in winmd though - like Code Contracts’ preconditions, invariants, and postconditions: those require directly executable (but pure, stateless, and side-effect-free) methods to represent and encode those contracts. As Winmd binaries can’t contain executable code it means you’re limited to only using “common”/“known” contract functions and/or resorting to re-encoding the contract to a string containing the expression that’s stored in an attribute. Good luck with that.
- pjmlp 6y agoWho does still use Code Contracts besides legacy code? They have been long dead.
- DaiPlusPlus 6y agoI was only using it as an example of a concept that isn't well-representable in winmd. As for CC specifically, I'd love to use it with .NET Core - I gather it doesn't need that much work to get going again. It's a shame Microsoft hasn't invested more into it, especially as there was talk of making CC an integral part of the C# syntax (as in, first-class support for `pure` functions in C# and a succinct syntax for attaching them as invariants/etc to C# types and methods). If this was done it would solve so many problems (e.g. compiler-enforced guarantees about which navigation-properties on Entity Framework entities are loaded) and maybe even elevate C# to compete with Ada and Eiffel for safety-critical systems!
- pjmlp 6y agoRequiring VS Enterprise to actually use them properly, doomed their adoption.
- pjmlp 6y agoWinRT/UAP/UWP (got to love marketing) is just COM as usual, with winmd instead of type libraries, IInspectable as base interface alongside IUnknown and extended ABI for generics, enums, arrays, structs. Here is a nice overview of the whole story and how interrelated COM and .NET are. https://arstechnica.com/features/2012/10/windows-8-and-winrt-everything-old-is-new-again/ https://arstechnica.com/features/2012/10/windows-8-and-winrt...