EnumPropsEx API in VB.NEt

G

Guest

Has anyone got working code using the EnumPropsEx API call in VB.NET. I have
several other API calls working to get info from other application windows,
but I can't seem to get this one working. Any help would be appreciated.
Here is the code I'm using currently (that doesn't work) I think I copied it
all in here correctly, but if I've missed something please let me know.

Thanks;
Shepard

Public Const GWL_EXSTYLE As Integer = (-20)
Public Const GW_OWNER As Integer = 4
Public Const SW_RESTORE As Integer = 9
Public Const SW_SHOW As Integer = 5
Public Const WS_EX_TOOLWINDOW As Integer = &H80
Public Const WS_EX_APPWINDOW As Integer = &H40000


' Declaration Section
Declare Function GetProp Lib "user32.dll" Alias "GetPropA" (ByVal hwnd
As Int32, ByVal lpString As String) As Int32
Declare Function SetProp Lib "user32.dll" Alias "SetPropA" ( _
ByVal hwnd As Int32, _
ByVal lpString As String, _
ByVal hData As Int32) As Int32
Private Declare Function RemoveProp Lib "user32.dll" Alias "RemovePropA"
(ByVal hwnd As Int32, ByVal lpString As String) As Int32
Private Declare Function EnumProps Lib "user32" Alias "EnumPropsA"
(ByVal hwnd As Integer, ByVal lpEnumFunc As Integer) As Long
Private Declare Function EnumPropsEx Lib "user32.dll" Alias
"EnumPropsExA" (ByVal hWnd As Int32, ByVal EnumPropCallback As
EnumPropCallback, ByVal lParam As Int32) As Int32
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA"
(ByVal lpString As String) As Int32
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA"
(ByVal lpString1 As String, ByVal lpString2 As String) As Int32
Delegate Function EnumPropCallback(ByVal hWnd As Integer, _
ByVal lpszString As Integer, _
ByVal hData As Integer, _
ByVal dwData As Integer) As
Int32

Public Declare Function EnumWindows Lib "user32.dll" _
Alias "EnumWindows" (ByVal callback As EnumWindowsCallback, _
ByVal lParam As Integer) As Integer

Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent _
As Integer, ByVal lpEnumFunc As EnumChildCallback, ByVal lParam As
Integer) As Integer

Public Delegate Function EnumChildCallback(ByVal hWnd As Integer, _
ByVal lParam As Integer) As
Boolean


Public Declare Function GetWindow Lib "user32.dll" _
Alias "GetWindow" (ByVal hwnd As Integer, _
ByVal wCmd As Integer) As Integer

Public Declare Function GetWindowLong Lib "user32.dll" _
Alias "GetWindowLongA" (ByVal hwnd As Integer, _
ByVal nIndex As Integer) As Integer





' Call back Function
Function PropEnumProc(ByVal hwnd As Integer, _
ByVal lpszString As Integer, ByVal hData As Integer, _
ByVal dwData As Integer) As
Int32
Dim Buffer As String
'create ab buffer
Buffer = Space(lstrlen(lpszString) + 1)
'copy the string to the buffer
lstrcpy(Buffer, lpszString)
'show the buffer
TextBox1.Text = Buffer
'continue enumeration
PropEnumProc = True
End Function

Function FillActiveWindowsList(ByVal hWnd As Integer, ByVal lParam As
Integer) As Boolean
Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH)

' Get the Window Caption.
GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH)

' Only add valid windows to the active windows listbox.
If ProcessIsActiveWindow(hWnd) Then
lstClassNames.Items.Add(windowText)
lstHandles.Items.Add(hWnd)
End If

Return True
End Function
Function ProcessIsActiveWindow(ByVal hWnd As Integer) As Boolean
Dim windowText As New StringBuilder(STRING_BUFFER_LENGTH)
Dim windowStyle As Integer

' Get the windows caption, owner information, and window style.
GetWindowText(hWnd, windowText, STRING_BUFFER_LENGTH)
Dim windowIsOwned As Boolean
windowIsOwned = GetWindow(hWnd, GW_OWNER) <> 0
windowStyle = GetWindowLong(hWnd,GWL_EXSTYLE)

' Do not allow invisible processes.
If Not IsWindowVisible(hWnd) Then
Return False
End If

' Window must have a caption
If windowText.ToString.Equals("") Then
Return False
End If

' Should not have a parent
If GetParent(hWnd) <> 0 Then
Return False
End If

' Don't allow unowned tool tips
If (windowStyle And WS_EX_TOOLWINDOW) <> 0 And Not windowIsOwned Then
Return False
End If

' Don't allow applications with owners
If (windowStyle And WS_EX_APPWINDOW) = 0 And windowIsOwned Then
Return False
End If

' All criteria were met, window is a valid active window.
Return True
End Function



Private Sub lstClassNames_DoubleClick(ByVal sender As Object, ByVal e As
System.EventArgs) Handles lstClassNames.DoubleClick
Dim hWnd As Integer
hWnd = lstHandles.Items(lstClassNames.SelectedIndex)
EnumPropsEx(hWnd, New EnumPropCallback(AddressOf _
PropEnumProc), 0)
Debug.Write("Error: " & Err.LastDllError())


End Sub

Private Sub Form_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
lstClassNames.Items.Clear()
lstClassNames.Enabled = True
EnumWindows(New EnumWindowsCallback(AddressOf _
FillActiveWindowsList), 0)


End Sub
 
G

Guest

I'm receiving the following dll error

Error number 126: The specified module could not be found.

As far as I can tell, I'm declaring it correctly and using it properly, but
I continue to get this error.

Thanks
Shepard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top