6 ms·
Win32‘s continued popularity (vs UWP) I’m sure has at least partially to do with how it’s all plain C, which makes it simple to support with any programming lan
by kitsunesoba 8y ago
Win32‘s continued popularity (vs UWP) I’m sure has at least partially to do with how it’s all plain C, which makes it simple to support with any programming language imaginable via bindings. If they were serious about pushing UWP adoption they should’ve provided plain C bindings for it so it could be used with Rust or Python or Swift or whatever. C# and C++ aren’t everybody’s cup of tea.
- pcwalton 8y agoWin32 isn't plain C. Lots of Win32 functionality is only accessible via COM, which is C++ (though using only a small subset of features so as to achieve ABI stability).
- ChrisSD 8y agoCOM isn't C++. It's a language independent interface. There's no reason why COM (and therefore UWP) can't be used from C.
- deleted 8y ago[deleted]
- userbinator 8y agoIt can be used from C but is a huge pain that makes it obvious whoever designed the interface (or COM in general) really went off the deep end with the abstraction level. There's a major difference between a C API designed to be used from C (Win32, POSIX) and one that only happens to be usable from C. Compare a sane "C API designed to be used from C": https://docs.microsoft.com/en-us/windows/desktop/dlgbox/using-common-dialog-boxes#opening-a-file https://docs.microsoft.com/en-us/windows/desktop/dlgbox/usin... that involves nothing more than initialising a structure and calling a single function, with MS's "recommended replacement" using COM: https://msdn.microsoft.com/en-us/library/Bb776913(v=VS.85).aspx#basic_usage https://msdn.microsoft.com/en-us/library/Bb776913(v=VS.85).a... That is a ten level deep nested if with just as many function calls, to do essentially the equivalent of the code above. The first time I saw this, I seriously thought they were taking the piss.
- pcwalton 8y agoAlso, that code isn't C, it's C++. Method calls are a C++ feature. While you could use COM without language support for method calls, because the ABI is stable, it isn't really something that Microsoft supports.
- teddyuk 8y agoI remember using C to call com components as a learning excercise - it was just that to see how it worked. You wouldn’t do it otherwise
- Iwan-Zotow 8y agoOf course Microsoft supports it, why not? There is no magic in COM, had COM object written in C
- pcwalton 8y agoI don't mean that calling COM objects from C doesn't work. I just mean that COM isn't designed to be used from C.
- tonyedgecombe 8y agoActually I think it was, that was the lowest common denominator.
- pjmlp 7y agoNot really, COM is a subset of OLE 2.0, designed to replace VBX as OCX originally. Naturally OLE was designed as C framework back in Win16 days, with endless pages of boilerplate code. https://www.amazon.com/Windows-Programmers-Guide-Book-Disk/dp/0672302268 https://www.amazon.com/Windows-Programmers-Guide-Book-Disk/d... As such COM can be called from C, specially since C++ Windows compilers have a VTBL layout as if they were a plain old C struct with function pointers. However unless one is masochist, it is not sane to use COM from bare bones C.
- Iwan-Zotow 8y agoCOM is COM, component object model, it is language-independent thing in itself
- srgpqt 8y agoPerhaps language-hostile would better describe it. Sure you can use it from any language that has some sort of ffi, but without compiler support it will not be pleasant.
- mastax 8y agoThis has improved recently. WinRT is basically just COM + IInspectable so it's possible to use from any language that supports the msvc abi. The gist is that Microsoft ships .midl files which can then be used to generate bindings. C++: https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/std-cpp-data-types https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-a... Rust: https://crates.io/crates/winrt https://crates.io/crates/winrt C: https://stackoverflow.com/questions/7436144/using-winrt-from-c https://stackoverflow.com/questions/7436144/using-winrt-from... etc.
- Varriount 8y agoHm. Where's the actual documentation on the MIDL format, or the ABI, or how it should be translated?
- deleted 8y ago[deleted]
- xlang 8y agoits open sourced https://github.com/Microsoft/xlang https://github.com/Microsoft/xlang kind of swig for com/winrt supporting just now only c++ and python https://github.com/Microsoft/xlang/wiki/xlang-faq https://github.com/Microsoft/xlang/wiki/xlang-faq
- mastax 8y agohttps://docs.microsoft.com/en-us/windows/desktop/midl/midl-start-page https://docs.microsoft.com/en-us/windows/desktop/midl/midl-s...
- dblohm7 8y agoCOM has always supported C. Go and look at any headers generated by MIDL and you’ll see a C variant of the interfaces. I don’t see why you couldn’t write a UWP app in pure C, you’d just need a shitload of boilerplate and glue to make it sane to work with. Though the C++ projection contains quite a bit of boilerplate itself, so... shrug