![]() |
Das Handle ist ungültig
Wie kann ich das beheben bzw. auf was muss ich achten?
Ich starte einen Stream vom Internet über den IE11 anschließend führe ich TAudioVolume aus. Bei normalen Prozessen ermittelt über die PID gibt es kein Problem. Aber wenn hier die Session erstellt und die Abfrage über den Prozess läuft bekomme ich oben genannte Fehlermeldung. Was kann man machen? Das selbe Problem habe ich auch wenn die Sidebar.exe erkannt wird.
Delphi-Quellcode:
FAudioSessionList[Index].SessionGuid := GroupGuid;
HR := SessionControl2.GetDisplayName(pDisplayName); if Succeeded(HR) then begin FAudioSessionList[Index].DisplayName := pDisplayName; if AudioSessionInfo(Index).DisplayName = '' then FAudioSessionList[Index].DisplayName := GetBaseNameFromPID(PID);
Delphi-Quellcode:
Siehe shot! Das wird angezeigt.
function TAudioVolume.GetBaseNameFromPID(const PID: DWORD): string;
var hProcess: THandle; path: array [0 .. MAX_PATH - 1] of WChar; ErrorTxt : array [0..500] of char; begin hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID); if hProcess <> 0 then try if GetModuleBaseName(hProcess, 0, path, MAX_PATH) = 0 then begin FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, ErrorTxt, 500, nil); ShowMessage(ErrorTxt); //RaiseLastOSError; end; Result := path; finally CloseHandle(hProcess) end else RaiseLastOSError; end; Aber ich kann den Prozess steuern also die Lautstärke desselben. Zudem bekomme ich so gut wie nie den DisplayName und den IconPath. Eigentlich müsste der DisplayName wie beim Pic stream.png sein. gruss |
AW: Das Handle ist ungültig
iexplore.exe besteht ja MINDESTENS aus zwei Process-Instanzen, wenn ich ihn bei mir hier starte und sonst nichts mache (laut Task-Manager).
Probiere doch mal die andere PID aus. |
AW: Das Handle ist ungültig
Zitat:
Danke. Auf der anderen seite wie soll ich den anderen ausprobieren ? Da habe ich keinen Einfluss drauf es wird die Session initialisiert die in dem Moment Sound wieder gibt! gruss |
AW: Das Handle ist ungültig
Versuch mal anstatt GetModuleBaseName die Funktion GetProcessImageFileNameW.
Beispiel:
Delphi-Quellcode:
program Project3;
{$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, Winapi.Windows, PsAPI; function GetProcessImageFileNameW(hProcess: THandle; lpBaseName: LPCWSTR; nSize: DWORD): DWORD; stdcall; external 'PSAPI.dll'; function GetBaseNameFromPID(const PID: DWORD): string; var hProcess: THandle; LModule: HMODULE; path: array [0 .. MAX_PATH - 1] of WideChar; ErrorTxt: array [0 .. 500] of WideChar; begin hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID); if hProcess <> 0 then try LModule := 0; path := ''; // if GetModuleBaseName(hProcess, LModule, path, MAX_PATH) = 0 then if GetProcessImageFileNameW(hProcess, path, MAX_PATH) = 0 then begin ErrorTxt := ''; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, nil, GetLastError, 0, ErrorTxt, 500, nil); Writeln(ErrorTxt); // RaiseLastOSError; end; Result := path; finally CloseHandle(hProcess) end else RaiseLastOSError; end; var gPID: DWORD; gName: string; begin try while True do begin Writeln('Bitte PID eingeben'); Readln(gPID); gName := GetBaseNameFromPID(gPID); Writeln(gName); end; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Readln; end; end; end. |
AW: Das Handle ist ungültig
Danke damit funktioniert es ;)
Aber! Zitat:
Verstehe nicht das da nie was ankommt. gruss |
AW: Das Handle ist ungültig
Wie machste das denn?
:glaskugel: Glaskugel sagt: Ohne genauen Quelltext keine Aussage! :glaskugel: |
AW: Das Handle ist ungültig
Zitat:
Delphi-Quellcode:
HR := SessionControl2.GetDisplayName(pDisplayName);
pDisplayName ist PWideChar und sollte den DisplayNamen zurück liefern tut er aber nicht. Bei keiner Anwendung. Wenn dieser leer ist erzwinge ich ihn das hat aber zur folge des er nicht korrekt ist. gruss |
AW: Das Handle ist ungültig
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?
|
AW: Das Handle ist ungültig
Zitat:
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:
gruss
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 |
AW: Das Handle ist ungültig
Zusatzfrage: Welchen Wert hat HR?
Delphi-Quellcode:
HR := SessionControl2.GetDisplayName(pDisplayName);
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 20:49 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz