AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

Das Handle ist ungültig

Ein Thema von EWeiss · begonnen am 2. Mai 2018 · letzter Beitrag vom 6. Mai 2018
Antwort Antwort
Seite 1 von 10  1 23     Letzte » 
EWeiss
(Gast)

n/a Beiträge
 
#1

Das Handle ist ungültig

  Alt 2. Mai 2018, 06:32
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:
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;
Siehe shot! Das wird angezeigt.
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

Geändert von EWeiss (11. Jul 2019 um 16:51 Uhr)
  Mit Zitat antworten Zitat
TiGü
Online

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#2

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 10:56
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.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#3

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 10:58
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.
Wenn ich den IE starte habe ich nur einen Prozess in der liste vom Taskmanager IExplorer.exe
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
  Mit Zitat antworten Zitat
TiGü
Online

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#4

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 11:25
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.
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#5

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 11:39
Danke damit funktioniert es
Aber!

Zitat:
Zudem bekomme ich so gut wie nie den DisplayName und den IconPath.
Das ist immer noch nicht bereinigt..
Verstehe nicht das da nie was ankommt.

gruss

Geändert von EWeiss (11. Jul 2019 um 16:51 Uhr)
  Mit Zitat antworten Zitat
TiGü
Online

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#6

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 11:54
Wie machste das denn?
Glaskugel sagt: Ohne genauen Quelltext keine Aussage!
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#7

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 12:02
Wie machste das denn?
Glaskugel sagt: Ohne genauen Quelltext keine Aussage!
Nun ja denke Quelltext dafür hatte ich gepostet oder?
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

Geändert von EWeiss ( 2. Mai 2018 um 12:06 Uhr)
  Mit Zitat antworten Zitat
TiGü
Online

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#8

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 12:08
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?
  Mit Zitat antworten Zitat
EWeiss
(Gast)

n/a Beiträge
 
#9

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 12: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
TiGü
Online

Registriert seit: 6. Apr 2011
Ort: Berlin
3.058 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: Das Handle ist ungültig

  Alt 2. Mai 2018, 12:15
Zusatzfrage: Welchen Wert hat HR?
HR := SessionControl2.GetDisplayName(pDisplayName);
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 10  1 23     Letzte » 

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 13:09 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