@@ -22,19 +22,37 @@ public Post21H2AudioPolicyConfig()
22
22
public void SetPersistedDefaultAudioEndpoint ( uint processId , EDataFlow flow , ERole role , string deviceId )
23
23
{
24
24
using var deviceIdHString = HSTRING . FromString ( deviceId ) ;
25
- Marshal . ThrowExceptionForHR ( ( int ) _factory . SetPersistedDefaultAudioEndpoint ( processId , flow , role , deviceIdHString ) ) ;
25
+ var result = _factory . SetPersistedDefaultAudioEndpoint ( processId , flow , role , deviceIdHString ) ;
26
+ if ( result != HRESULT . S_OK && result != HRESULT . PROCESS_NO_AUDIO )
27
+ {
28
+ throw new InvalidComObjectException ( $ "Can't set the persistent audio endpoint: { result } ") ;
29
+ }
26
30
}
27
31
28
32
public string GetPersistedDefaultAudioEndpoint ( uint processId , EDataFlow flow , ERole role )
29
33
{
30
- _factory . GetPersistedDefaultAudioEndpoint ( processId , flow , role , out var deviceId ) ;
34
+ var result = _factory . GetPersistedDefaultAudioEndpoint ( processId , flow , role , out var deviceId ) ;
35
+ if ( result != HRESULT . S_OK )
36
+ {
37
+ if ( result != HRESULT . PROCESS_NO_AUDIO )
38
+ {
39
+ throw new InvalidComObjectException ( $ "Can't set the persistent audio endpoint: { result } ") ;
40
+ }
41
+
42
+ return null ;
43
+ }
44
+
31
45
var deviceIdStr = deviceId . ToString ( ) ;
32
46
deviceId . Dispose ( ) ;
33
47
return deviceIdStr ;
34
48
}
35
49
36
50
public void ClearAllPersistedApplicationDefaultEndpoints ( )
37
51
{
38
- Marshal . ThrowExceptionForHR ( ( int ) _factory . ClearAllPersistedApplicationDefaultEndpoints ( ) ) ;
52
+ var result = _factory . ClearAllPersistedApplicationDefaultEndpoints ( ) ;
53
+ if ( result != HRESULT . S_OK && result != HRESULT . PROCESS_NO_AUDIO )
54
+ {
55
+ throw new InvalidComObjectException ( $ "Reset audio endpoints: { result } ") ;
56
+ }
39
57
}
40
58
}
0 commit comments