First create a delegate that will represent your EnumFunc like so ...
Public Delegate Function EnumFuncDeleg(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
Then change this API declaration like so ...
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As EnumFuncDeleg, ByVal lParam As Integer) As Integer
Then your code should work. Basically .NET will automatically marshal (convert behind the scenes) the EnumFuncDeleg delegate into a 32 bit function pointer, for the win32 api function to succeed.
: Hi,
:
: I am trying to find a MSN Chat window so I can close it down programtically.. Well eventually I will hide it not close it..
:
: Anyway, I have converted some working VB6 code to net.
:
: The code is as follows:
: <Code>
: Option Strict Off
: Option Explicit On
: Module Module1
:
: Public Const MAX_PATH As Short = 260
: Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Integer, ByVal lParam As Integer) As Integer
: Declare Function GetClassName Lib "user32" Alias "GetClassNameA"(ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
: Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"(ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
: Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
: Public Const WM_CLOSE As Short = &H10s
:
:
:
: Public Function EnumFunc(ByVal hwnd As Integer, ByVal lpData As Integer) As Integer
: Dim lResult As Integer
: Dim sWndName As String
: Dim szClassName As String
:
: EnumFunc = 1
: szClassName = Space(MAX_PATH)
: sWndName = Space(MAX_PATH)
:
: lResult = GetClassName(hwnd, szClassName, MAX_PATH)
: szClassName = Left(szClassName, lResult)
:
: lResult = GetWindowText(hwnd, sWndName, MAX_PATH)
: sWndName = Left(sWndName, lResult)
:
: Dim vreturnvalue As Object
: If InStr(sWndName, "Conversation") > 0 Then
: 'UPGRADE_WARNING: Couldn't resolve default property of object vreturnvalue. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
: vreturnvalue = SendMessage(hwnd, WM_CLOSE, &O0s, &O0s)
: End If
:
: End Function
:
: Public Function fEnumWindows() As Boolean
: Dim hwnd As Integer
: 'UPGRADE_WARNING: Add a delegate for AddressOf EnumFunc Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
: Call EnumWindows(AddressOf EnumFunc, hwnd)
: End Function
: End Module
: </Code>
: but in true .Net fashion it has an error..
: Which is:
: Error 1 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type.
:
: Can anyone point me in the direction of a fix.
:
: OR..
:
: Knock up some code which can find and hide the window..
: Cheers
: Michael Hudson
: Select
:
: