micropathic
Well-known member
- Joined
- Oct 23, 2003
- Messages
- 75
Let me just start off by saying Im a bit of a noob and I know my code is pretty. However for learning purposes I just need to figure out how to make the following code work in .net.
The code is designed to kill another instance of an app using sendmessage and the windows name. Ive searched the forum for a better alternative to using sendmessage, but had no luck with the code I found. The problem with the code right now seems to be with "lhWnd"s type as vb.net throws an invalid cast exception when I try to run it. Any suggestions?
Thanks in advance!
[VB]
Const WM_CLOSE As Integer = &H10s
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Integer
Private Sub Form_Load()
If (UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0) Then
GoTo ChangeCaptionName
Else
GoTo SkipChangeCaptionName
End If
ChangeCaptionName:
Dim lhWnd As long
Dim r As Short
Me.Text = "*" & Me.Text
lhWnd = FindWindow(vbNullString, "Rubber Stamped Sync")
If lhWnd <> 0 Then
MsgBox lhWnd
*************LINE BELOW THIS IS THE PROBLEM*********
r = SendMessage(lhWnd, WM_CLOSE, 0, 0)
MsgBox lhWnd
End If
MsgBox lhWnd
Me.Text = Mid(Me.Text, 2)
SkipChangeCaptionName:
End Sub
[/VB]
The code is designed to kill another instance of an app using sendmessage and the windows name. Ive searched the forum for a better alternative to using sendmessage, but had no luck with the code I found. The problem with the code right now seems to be with "lhWnd"s type as vb.net throws an invalid cast exception when I try to run it. Any suggestions?
Thanks in advance!
[VB]
Const WM_CLOSE As Integer = &H10s
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As IntPtr, _
ByVal wMsg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Long) As Integer
Private Sub Form_Load()
If (UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0) Then
GoTo ChangeCaptionName
Else
GoTo SkipChangeCaptionName
End If
ChangeCaptionName:
Dim lhWnd As long
Dim r As Short
Me.Text = "*" & Me.Text
lhWnd = FindWindow(vbNullString, "Rubber Stamped Sync")
If lhWnd <> 0 Then
MsgBox lhWnd
*************LINE BELOW THIS IS THE PROBLEM*********
r = SendMessage(lhWnd, WM_CLOSE, 0, 0)
MsgBox lhWnd
End If
MsgBox lhWnd
Me.Text = Mid(Me.Text, 2)
SkipChangeCaptionName:
End Sub
[/VB]