
Windows Implementation Libraries: type-safe C++ interfaces for Windows patterns - ingve
https://github.com/Microsoft/wil
======
jchw
Here’s what I don’t get.

Microsoft has been shipping a C++ compiler for decades, and for the most part
it is the preferred language for Windows development even today.

Moreover, there have been PLENTY of libraries designed to make it easier, like
MFC, ATL, etc.

Why didn’t this already exist?!

Like I realize some of it is modern C++ and maybe Microsoft was not focusing
on desktop when C++ had these innovations. But why not smart pointers for
handles, error handling macros, etc. Crazy.

Lateness aside, I still occasionally do write win32 stuff, usually to
extend/compliment/hack upon existing win32 stuff. So this is probably going to
become a goto library now, if its as good as it sounds.

~~~
oldmanhorton
Well, this has existed, but it's been internal to Microsoft (perhaps only
internal to the windows team? That's the only place I've seen it). It's just
taken a while to slowly open source more and more internal tools

~~~
snaky
> Windows Template Library (WTL) is a free software, object-oriented C++
> template library for Win32 development. WTL was created by Microsoft
> employee Nenad Stefanovic for internal use and later released as an
> unsupported add-on to Visual Studio and the Win32 Framework SDK. It was
> developed primarily as a light-weight alternative to the Microsoft
> Foundation Classes and builds upon Microsoft's ATL, another lightweight API
> widely used to create COM and ActiveX libraries.

[https://en.wikipedia.org/wiki/Windows_Template_Library](https://en.wikipedia.org/wiki/Windows_Template_Library)

~~~
contextfree
Not the same thing

------
lenkite
Also check out C++/WinRT - a _pure_ C++17 library facade over WinRT/UWP API's.
[https://docs.microsoft.com/en-us/windows/uwp/cpp-and-
winrt-a...](https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-
apis/intro-to-using-cpp-with-winrt)

~~~
doublerebel
WinRT + coroutines makes modern Windows programming _amazing_ to write and
read, and efficient to run. This plus the xlang (compiler? toolset?) system,
all open-sourced, shows how Microsoft has hedged against whichever platform
will win the next round. Kenny Kerr deserves much credit for pushing all of
C++ forward with these concepts.

------
TillE
Oh wow, this is exactly what I've always wanted in my many many years of
developing Windows software in C++.

Despite a million fancy new API layers in newer versions of Windows, Win32 is
very much not dead, but it's still a C interface with a lot of clunky and
inconsistent nonsense. This looks like the ideal modern C++ wrapper for all
that.

~~~
stinos
It looks pretty usable indeed, I just wish they had insludes std::error_code
implementations for everything. Last time I checked, getting proper
error_codes (i.e. which can be compared against standard categories and which
have good error description strings) for everything in the API was still some
manual work.

~~~
aninteger
It's not too hard. Just write a simple wrapper around FormatMessage:

    
    
      DWORD errorCode = GetLastError();
    
      DWORD dwFlg = FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |    FORMAT_MESSAGE_IGNORE_INSERTS;
      LPTSTR lpMsgBuf = NULL;
      FormatMessageA(dwFlg, 0, errorCode, 0, (LPTSTR)&lpMsgBuf, 0, NULL);
    
      // Error message is in lpMsgBuf so make sure to free afterwards.
      LocalFree(lpMsgBuf);

~~~
ksherlock
It's even easier since the MSVC STL std::error_code (std::system_category)
already does that.

------
dmytroi
This is quite nice! I like the error handler monitor thing. Also quite amazing
that they placed whole platform-independent (sort of) thread local storage
implementation there.

------
zmodem
> If you are doing any non-trivial work, also be sure to have a recent version
> of Clang installed.

Nice to see Clang being put to good use on Windows.

~~~
sorenjan
But why do you need two compilers?

~~~
jhasse
Microsoft tried to lock developers in with MSVC, but it didn't work. Now we
have to wait for it to die, so that we can use Clang instead.

