-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #168 from XScorpion2/set_default_device_api
Implemented IPolicyConfig interface for set default device
- Loading branch information
Showing
3 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using CSCore.CoreAudioAPI; | ||
using CSCore.Win32; | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MaxMix.Services.Audio | ||
{ | ||
[Guid("8F9FB2AA-1C0B-4D54-B6BB-B2F2A10CE03C")] | ||
class PolicyConfig : ComObject | ||
{ | ||
public PolicyConfig() : base(CreatePolicyConfig()) { } | ||
|
||
private static IntPtr CreatePolicyConfig() | ||
{ | ||
var obj = new PolicyConfigObject(); | ||
if (obj is IPolicyConfig c) | ||
return Marshal.GetComInterfaceForObject(c, typeof(IPolicyConfig)); | ||
throw new NotSupportedException("Unable to create PolicyConfig on this OS."); | ||
} | ||
|
||
public void SetDefaultEndpoint(string id, Role role) | ||
{ | ||
var obj = Marshal.GetObjectForIUnknown(BasePtr); | ||
int result = unchecked((int)0x80090011); // Object not found error | ||
if (obj is IPolicyConfig c) | ||
result = c.SetDefaultEndpoint(id, role); | ||
Marshal.ThrowExceptionForHR(result); | ||
} | ||
|
||
[ComImport] | ||
[Guid("870AF99C-171D-4F9E-AF0D-E63DF40C2BC9")] | ||
private class PolicyConfigObject | ||
{ | ||
} | ||
} | ||
|
||
[ComImport] | ||
[Guid("F8679F50-850A-41CF-9C72-430F290290C8")] | ||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | ||
interface IPolicyConfig : IUnknown | ||
{ | ||
void Unused1(); | ||
void Unused2(); | ||
void Unused3(); | ||
void Unused4(); | ||
void Unused5(); | ||
void Unused6(); | ||
void Unused7(); | ||
void Unused8(); | ||
void Unused9(); | ||
void Unused10(); | ||
int SetDefaultEndpoint([In, MarshalAs(UnmanagedType.LPWStr)] string id, Role role); | ||
void Unused12(); | ||
} | ||
} |