Thema: Delphi Das Handle ist ungültig

Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#9

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 11:15
Was ist SessionControl2? Wo kommt es her? Wie wird es erzeugt? Was ist der Datentyp? Ist das ein Interface? Wie ist die Definition des Interfaces?
Delphi-Quellcode:
unit AudioSessionControl;

interface

uses
  Windows, Messages, Classes, AudioSessionEvents;

const
  IID_IAudioSessionControl: TGUID = '{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}';

type
  IAudioSessionControl = interface(IUnknown)
    ['{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}']
    function GetState(out pRetVal: uint): HResult; stdcall;
    function GetDisplayName(out pRetVal: LPWSTR): HResult; stdcall;
    function SetDisplayName(Value: LPCWSTR; EventContext: pGuid): HResult; stdcall;
    function GetIconPath(out pRetVal: LPWSTR): HResult; stdcall;
    function SetIconPath(Value: LPCWSTR; EventContext: pGuid): HResult; stdcall;
    function GetGroupingParam(pRetVal: pGuid): HResult; stdcall;
    function SetGroupingParam(OverrideValue, EventContext: pGuid): HResult; stdcall;
    function RegisterAudioSessionNotification(const NewNotifications: IAudioSessionEvents)
      : HResult; stdcall;
    function UnregisterAudioSessionNotification(const NewNotifications: IAudioSessionEvents)
      : HResult; stdcall;
  end;

implementation

end.
Delphi-Quellcode:
unit AudioSessionControl2;

interface

uses
  Windows, Messages, Classes, AudioSessionControl;

const
  IID_IAudioSessionControl2: TGUID = '{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}';

type
  IAudioSessionControl2 = interface(IAudioSessionControl)
    ['{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}']
    function GetSessionIdentifier(out pRetVal: LPWSTR): Hresult; stdcall;
    function GetSessionInstanceIdentifier(out pRetVal: LPWSTR): Hresult; stdcall;
    function GetProcessId(out pRetVal: DWord): Hresult; stdcall;
    //indicates whether the session is a system sounds session.
    function IsSystemSoundsSession(): Hresult; stdcall;
    //S_OK = The session is a system sounds session.
    //S_FALSE = The session is not a system sounds session.
    function SetDuckingPreference(const optOut: Boolean): Hresult; stdcall;
    //A BOOL variable that enables or disables system auto-ducking.
  end;

implementation

end.
Delphi-Quellcode:
SessionControl2: IAudioSessionControl2;
....
    HR := AudioDevice.Activate(IID_IAudioSessionManager2, CLSCTX_ALL, nil, IUnknown(SessionManager2)
      );
    if Succeeded(HR) then
    begin
      HR := SessionManager2.GetSessionEnumerator(pEnumerator);
      if Succeeded(HR) then
      begin
        HR := pEnumerator.GetSession(Index, SessionControl);
        if Succeeded(HR) then
        begin
          HR := SessionControl.QueryInterface(IAudioSessionControl2, SessionControl2);
          if Succeeded(HR) then
gruss
  Mit Zitat antworten Zitat