AW: Das Handle ist ungültig
Zitat:
gruss |
AW: Das Handle ist ungültig
Das mit dem unvollständigen Quelltext-Schnipseln ist mir so zu mühselig.
Lade bitte ein kleines Konsolenprojekt mit allen notwendigen Units und Dateien als ZIP-Archiv hoch. |
AW: Das Handle ist ungültig
Zitat:
Schicke ihn dir aber gerne zu wenn ich eine Mail hätte. gruss |
AW: Das Handle ist ungültig
Das ist ein Forum.
Man stellt öffentlich Fragen und erhält öffentlich Antworten. Es hätte keinen Sinn für nachfolgende Programmierergenerationen, wenn die eventuell folgende Lösung nur noch per internen Mailverkehr abläuft. Ein kleines Beispielprogramm mit allen notwendigen Units wird ja möglich sein. Anders machen das andere User ja auch nicht, wenn ihnen geholfen werden soll. Mit den Quellcode Schnipseln kann ich bspw. nix anfangen, da ich weder die Unit AudioSessionEvents habe, noch die Definition von AudioDevice oder SessionManager2. So ist das nur unvollständiges Stückwerk. |
AW: Das Handle ist ungültig
Zitat:
Ok macht ja nix muss mir dann selbst irgendwie weiter helfen. Danke gruss |
AW: Das Handle ist ungültig
Komplett lauffähiges Konsolenprogramm, alles in einer einzigen Unit.
Gibt bei mir aus:
Code:
DisplayName: @%SystemRoot%\System32\AudioSrv.Dll,-202
IconPath: @%SystemRoot%\System32\AudioSrv.Dll,-203
Delphi-Quellcode:
program AudioDevice;
{$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, Winapi.Windows, Winapi.ActiveX, Winapi.PropSys; const IID_IAudioSessionControl: TGUID = '{F4B1A599-7266-4319-A8CA-E70ACB11E8CD}'; IID_IAudioSessionControl2: TGUID = '{bfb7ff88-7239-4fc9-8fa2-07c950be9c6d}'; IID_IAudioSessionManager: TGUID = '{BFA971F1-4D5E-40BB-935E-967039BFBEE4}'; IID_IAudioSessionManager2: TGUID = '{77AA99A0-1BD6-484F-8BC7-2C654C9A9B6F}'; CLASS_IMMDeviceEnumerator: TGUID = '{BCDE0395-E52F-467C-8E3D-C4579291692E}'; IID_IMMDeviceEnumerator: TGUID = '{A95664D2-9614-4F35-A746-DE8DB63617E6}'; IID_IMMDevice: TGUID = '{D666063F-1587-4E43-81F1-B948E807363F}'; IID_IMMDeviceCollection: TGUID = '{0BD7A1BE-7A1A-44DB-8397-CC5392387B5E}'; IID_IMMAudioEndpointVolume: TGUID = '{5CDF2C82-841E-4546-9722-0CF74078229A}'; IID_IAudioMeterInformation: TGUID = '{C02216F6-8C67-4B5B-9D00-D008E73E0064}'; IID_IAudioEndpointVolumeCallback: TGUID = '{657804FA-D6AD-4496-8A60-352752AF4F89}'; IID_IMMNotificationClient: TGUID = '{7991EEC9-7E89-4D85-8390-6C703CEC60C0}'; DEVICE_STATE_ACTIVE = $00000001; DEVICE_STATE_UNPLUGGED = $00000002; DEVICE_STATE_NOTPRESENT = $00000004; DEVICE_STATEMASK_ALL = $00000007; type EDataFlow = TOleEnum; const eRender = $00000000; eCapture = $00000001; eAll = $00000002; EDataFlow_enum_count = $00000003; type ERole = TOleEnum; const eConsole = $00000000; eMultimedia = $00000001; eCommunications = $00000002; ERole_enum_count = $00000003; type IAudioSessionEvents = interface end; 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; IAudioSessionControl2 = interface(IAudioSessionControl) [IID_IAudioSessionControl2] 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; IAudioSessionEnumerator = interface(IUnknown) ['{E2F5BB11-0570-40CA-ACDD-3AA01277DEE8}'] function GetCount(out SessionCount: Integer): HRESULT; stdcall; function GetSession(const SessionCount: Integer; out Session: IAudioSessionControl): HRESULT; stdcall; end; IAudioSessionNotification = interface end; IAudioVolumeDuckNotification = interface end; ISimpleAudioVolume = interface(IUnknown) ['{87CE5498-68D6-44E5-9215-6DA47EF883D8}'] function SetMasterVolume(fLevel: Single; EventContext: pGuid): HRESULT; stdcall; function GetMasterVolume(out fLevel: Single): HRESULT; stdcall; function SetMute(bMute: LongBool; EventContext: pGuid): HRESULT; stdcall; function GetMute(out bMute: LongBool): HRESULT; stdcall; end; IAudioSessionManager = interface(IUnknown) [IID_IAudioSessionManager] function GetAudioSessionControl(AudioSessionGuid: pGuid; StreamFlag: uint; out SessionControl: IAudioSessionControl) : HRESULT; stdcall; function GetSimpleAudioVolume(AudioSessionGuid: pGuid; StreamFlag: uint; out AudioVolume: ISimpleAudioVolume) : HRESULT; stdcall; end; IAudioSessionManager2 = interface(IAudioSessionManager) [IID_IAudioSessionManager2] function GetSessionEnumerator(out SessionEnum: IAudioSessionEnumerator): HRESULT; stdcall; function RegisterSessionNotification(SessionNotification: IAudioSessionNotification): HRESULT; stdcall; function UnregisterSessionNotification(SessionNotification: IAudioSessionNotification): HRESULT; stdcall; function RegisterDuckNotification(const sessionID: LPCWSTR; const duckNotification: IAudioVolumeDuckNotification) : HRESULT; stdcall; function UnregisterDuckNotification(const duckNotification: IAudioVolumeDuckNotification): HRESULT; stdcall; end; IAudioEndpointVolumeCallback = interface(IUnknown) [IID_IAudioEndpointVolumeCallback] end; IMMAudioEndpointVolume = interface(IUnknown) [IID_IMMAudioEndpointVolume] function RegisterControlChangeNotify(AudioEndPtVol: IAudioEndpointVolumeCallback): Integer; stdcall; function UnregisterControlChangeNotify(AudioEndPtVol: IAudioEndpointVolumeCallback): Integer; stdcall; function GetChannelCount(out PInteger): Integer; stdcall; function SetMasterVolumeLevel(fLevelDB: Double; pguidEventContext: TGUID): Integer; stdcall; function SetMasterVolumeLevelScalar(fLevelDB: Double; pguidEventContext: TGUID): Integer; stdcall; function GetMasterVolumeLevel(out fLevelDB: Double): Integer; stdcall; function GetMasterVolumeLevelScaler(out fLevel: Double): Integer; stdcall; function SetChannelVolumeLevel(nChannel: Integer; fLevelDB: Double; pguidEventContext: TGUID): Integer; stdcall; function SetChannelVolumeLevelScalar(nChannel: Integer; fLevelDB: Double; pguidEventContext: TGUID): Integer; stdcall; function GetChannelVolumeLevel(nChannel: Integer; out fLevelDB: Double): Integer; stdcall; function GetChannelVolumeLevelScalar(nChannel: Integer; out fLevel: Double): Integer; stdcall; function SetMute(bMute: Boolean; pguidEventContext: TGUID): Integer; stdcall; function GetMute(out bMute: Boolean): Integer; stdcall; function GetVolumeStepInfo(pnStep: Integer; out pnStepCount: Integer): Integer; stdcall; function VolumeStepUp(pguidEventContext: TGUID): Integer; stdcall; function VolumeStepDown(pguidEventContext: TGUID): Integer; stdcall; function QueryHardwareSupport(out pdwHardwareSupportMask): Integer; stdcall; function GetVolumeRange(out pflVolumeMindB: Double; out pflVolumeMaxdB: Double; out pflVolumeIncrementdB: Double) : Integer; stdcall; end; IMMDevice = interface(IUnknown) [IID_IMMDevice] function Activate(const iid: TGUID; dwClsCtx: uint; pActivationParams: PPropVariant; out ppInterface: IUnknown) : HRESULT; stdcall; function OpenPropertyStore(stgmAccess: Integer; out ppProperties: IPropertyStore): HRESULT; stdcall; function GetId(ppstrId: PWChar): HRESULT; stdcall; function GetState(var pdwState: uint): HRESULT; stdcall; end; IMMDeviceCollection = interface(IUnknown) [IID_IMMDeviceCollection] function GetCount(var pcDevices: uint): HRESULT; stdcall; function Item(nDevice: uint; out ppDevice: IMMDevice): HRESULT; stdcall; end; IMMNotificationClient = interface(IUnknown) [IID_IMMNotificationClient] end; IMMDeviceEnumerator = interface(IUnknown) [IID_IMMDeviceEnumerator] function EnumAudioEndpoints(dataFlow: EDataFlow; dwStateMask: DWord; out ppDevices: IMMDeviceCollection): HRESULT; stdcall; function GetDefaultAudioEndpoint(dataFlow: EDataFlow; role: ERole; out ppEndpoint: IMMDevice): HRESULT; stdcall; function GetDevice(pwstrId: PWChar; out ppDevice: IMMDevice): HRESULT; stdcall; function RegisterEndpointNotificationCallback(var pClient: IMMNotificationClient): HRESULT; stdcall; function UnregisterEndpointNotificationCallback(var pClient: IMMNotificationClient): HRESULT; stdcall; end; procedure PrintDefaultSessionControlDisplayName; var DeviceEnumerator: IMMDeviceEnumerator; SessionManager: IAudioSessionManager; SessionManager2: IAudioSessionManager2; AudioDevice: IMMDevice; SessionControl2: IAudioSessionControl2; SessionEnumerator: IAudioSessionEnumerator; SessionControl: IAudioSessionControl; HR: HRESULT; SessionCount: Integer; pRetVal: PWideChar; begin SessionCount := 0; HR := CoInitializeEx(nil, 0); if Succeeded(HR) then begin HR := CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, DeviceEnumerator); if Succeeded(HR) then begin HR := DeviceEnumerator.GetDefaultAudioEndpoint(eRender, eConsole, AudioDevice); if Succeeded(HR) then begin HR := AudioDevice.Activate(IID_IAudioSessionManager, CLSCTX_INPROC_SERVER, nil, IUnknown(SessionManager)); if Succeeded(HR) then begin if Supports(SessionManager, IID_IAudioSessionManager2, SessionManager2) then begin HR := SessionManager2.GetSessionEnumerator(SessionEnumerator); if Succeeded(HR) then begin HR := SessionEnumerator.GetSession(SessionCount, SessionControl); if Succeeded(HR) then begin if Supports(SessionControl, IID_IAudioSessionControl2, SessionControl2) then begin SessionControl2.GetDisplayName(pRetVal); Writeln('DisplayName: ', pRetVal); CoTaskMemFree(pRetVal); SessionControl2.GetIconPath(pRetVal); Writeln('IconPath: ', pRetVal); CoTaskMemFree(pRetVal); end; end; end; end; end; end; end; CoUninitialize; end; end; begin try PrintDefaultSessionControlDisplayName; Readln; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Readln; end; end; end. |
AW: Das Handle ist ungültig
Sieht gut aus..)
Muss das mal mit meiner Herangehensweise vergleichen. Bin auch schon was weiter wenn auch mit ach und krach muss noch einiges optimiert werden. Zum Beispiel scheint MS die SideBar zu kombinieren. Bei mir wird für jedes das Sound enthält ein Control erstellt. Danke. gruss |
AW: Das Handle ist ungültig
Nope habe deine Funktion testweise mal eingebaut da kommt nichts an.
Beides bleibt leer. ........... Dein Projekt ohne Änderung kompiliert D2010 Siehe das Ergebnis. Sollte eigentlich den Namen und den IconPfad meiner Anwendung anzeigen.Tut's aber nicht. Und wenn ich die Konsole vorher starte und anschließend ein Sound Programm stürzt das Konsolen teil ab. Hmmm.. vielleicht lege ich das Projekt erst mal zur Seite. Hier die Änderung damit es nicht mehr abstürzt. Aber funktionieren tut es trotzdem nicht. (Win7 Problem? Keine Ahnung)
Delphi-Quellcode:
gruss
procedure PrintDefaultSessionControlDisplayName;
var DeviceEnumerator: IMMDeviceEnumerator; SessionManager: IAudioSessionManager; SessionManager2: IAudioSessionManager2; AudioDevice: IMMDevice; SessionControl2: IAudioSessionControl2; SessionEnumerator: IAudioSessionEnumerator; SessionControl: IAudioSessionControl; HR: HRESULT; SessionCount: Integer; pRetVal: PWideChar; begin SessionCount := 0; HR := CoInitializeEx(nil, 0); if Succeeded(HR) then begin HR := CoCreateInstance(CLASS_IMMDeviceEnumerator, nil, CLSCTX_ALL, IID_IMMDeviceEnumerator, DeviceEnumerator); if Succeeded(HR) then begin HR := DeviceEnumerator.GetDefaultAudioEndpoint(eRender, eConsole, AudioDevice); if Succeeded(HR) then begin HR := AudioDevice.Activate(IID_IAudioSessionManager, CLSCTX_INPROC_SERVER, nil, IUnknown(SessionManager)); if Succeeded(HR) then begin if Supports(SessionManager, IID_IAudioSessionManager2, SessionManager2) then begin HR := SessionManager2.GetSessionEnumerator(SessionEnumerator); if Succeeded(HR) then begin HR := SessionEnumerator.GetSession(SessionCount, SessionControl); if Succeeded(HR) then begin if Supports(SessionControl, IID_IAudioSessionControl2, SessionControl2) then begin SessionControl2.GetDisplayName(pRetVal); Writeln('DisplayName: ', pRetVal); CoTaskMemFree(pRetVal); SessionControl2.GetIconPath(pRetVal); Writeln('IconPath: ', pRetVal); CoTaskMemFree(pRetVal); end; SessionControl2 := nil; end; SessionControl := nil; end; SessionEnumerator := nil; end; SessionManager2 := nil; end; SessionManager := nil; end; end; DeviceEnumerator := nil; CoUninitialize; end; end; |
AW: Das Handle ist ungültig
Bei mir wird es auch korrekt angezeigt, aber unter Windows 10. Windows 7 habe ich leider nicht zur Verfügung zum Testen.
|
AW: Das Handle ist ungültig
Zitat:
Ich kann machen was ich will beide WideChars ergeben immer .. nothing. :) Ein
Delphi-Quellcode:
if Supports(SessionControl
Ist nicht unbedingt nötig denn wenn ich ein query auf SessionControl2 ausführe würde es wenn nicht unterstützt eh fehl schlagen. so..
Delphi-Quellcode:
HR := SessionControl.QueryInterface(IAudioSessionControl2, SessionControl2);
oder so
Delphi-Quellcode:
if Supports(SessionManager, IID_IAudioSessionManager2, SessionManager2) then
bleibt sich gleich. Mein Test bezieht sich auf das von mir korrigierte Obige Schnipsel. Alle Test's schlagen fehl. gruss |
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:31 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz