WASAPI Loopback: Save wave file

I want to record the system’s audio output using WASAPI and then saving it to a .wav file. So far I’ve followed these guides on WASAPI: https://msdn.microsoft.com/en-us/library/windows/desktop/…