/// <summary>
 /// Helper function to automatically raise an exception on failure.
 /// </summary>
 /// <param name="result">The result of the API call.</param>
 /// <param name="function">The API function name.</param>
 internal static void Try(LegacyAudioResult result, string function)
 {
     if (result != LegacyAudioResult.NoError)
     {
         throw new LegacyAudioException(result, function);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="LegacyAudioException"/> class.
 /// </summary>
 /// <param name="result">The result returned by the Windows API call.</param>
 /// <param name="functionName">The name of the Windows API that failed.</param>
 public LegacyAudioException(LegacyAudioResult result, string functionName)
     : base(ErrorMessage(result, functionName))
 {
     Result       = result;
     FunctionName = functionName;
 }
 /// <summary>
 /// Creates an error message base don an error result.
 /// </summary>
 /// <param name="result">The result.</param>
 /// <param name="function">The function.</param>
 /// <returns>A descriptive error message.</returns>
 private static string ErrorMessage(LegacyAudioResult result, string function) => $"{result} calling {function}";