Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Frage zu GetWindowThreadProcessId

Empfohlene Antworten

Veröffentlicht

Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hwnd As int32, lpdwProcessId As int32) As int32

Ich möchte die ProcessID auslesen bekomme aber immer nur 0 zurück. Weiß jemand an was das liegt? Gibt es noch eine andere Möglichkeit an die PID zu kommen, wenn ja, welche?

OS: Win XP

Zum Testen versuche ich vom Windows Rechner eine PID zu bekommen. Über FindWindow hol ich das Handle auf den Rechner und über EnumChildWindow hole ich den rest.

egal, ob ich das mainhandle nehme, oder die Kinderhandle, es wird immer 0 geliefert.

Danke für eure Hilfe.

PS: Seh ich das richtig: Ein Prozess ist ein einzelnes Programm? Prozesse bestehen aus Threads und innerhalb der Threads haben versch. Elemente Handles.

Haben alle Steuerelemente Handles?

Hi,

in diesem Fall darfst du nicht den Rückgabewert der Funktion überprüfen sondern musst den zweiten Parameter untersuchen:

Die MSDN sagt folgendes:

The GetWindowThreadProcessId function retrieves the identifier of the thread

that created the specified window and, optionally, the identifier of the process that created the window.

Syntax

DWORD GetWindowThreadProcessId(HWND hWnd, LPDWORD lpdwProcessId);

Parameters

hWnd

[in] Handle to the window.

lpdwProcessId

[out] Pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.

Return Value

The return value is the identifier of the thread that created the window.

Hätte vielleicht auch sagen sollen, dass es der zweite Parameter ist, der immer 0 ist.

Deine Funktionsdeklaration sieht wie VB aus. Wie rufst du die Funktion denn auf? Weist du dem zweiten Parameter vorher etwas zu? Die funktion erwartet hier eine Zeigervariable.

Jup, wird in VB.NET gemacht.

Hab eine Variable deklariert:

dim i as int32

i = nothing

die hab ich dann übergeben, einmal als nothing, einmal ohne Wertzuweisung, einmal mit Wert.

Mit Wert wirft die Methode wie erwartet eine Eception.

Ich glaub, ich hab auch schonmal nur nen Object übergeben. Das sind ja an und für sich alles 4 Byte-Zeiger.

Vielleicht wenn du es als IntPtr übergibst?

Keine Ahnung, warum das auch nicht funktioniert.

Wenn ich einen String nehme, kommt eine sinnfreie Zeichenfolge heraus. Eventuell ist das die PID. Muss die dann halt nur noch in nen integer Konvertieren.

Wie ist denn die Syntax für das C# Keyword 'out' in VB .Net?

wie meinst du das mit dem 'out' ?

writeline("") für Konsolenausgabe?

ByVal und ByRef bei den Parametern?

'out' Parameter sind in C# die "klassischen" C++ Zeiger (LPDWORD in deinem Fall). Da ich in VB. Net nicht so fit bin weiß ich nicht wie das hier heißt (ByRef, ByVal)

  • 2 Jahre später...

Hallo ich habs wiefolgt probiert:

Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal windowsHandle As IntPtr, ByVal windowsProcessId As IntPtr) As IntPtr

Dann: Dim handle as IntPtr = FindWindow(Nothing, "Fenstertext")

nun nur noch:

Dim procId as IntPtr

procId = IntPtr.Zero

und : procId = GetWindowThreadProcessId(handle, IntPtr.Zero)

Es steht bei mir also nicht im 2. Wert sondern tatsache im Rückgabewert die korrete Id drin.

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.