By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,091 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,091 IT Pros & Developers. It's quick & easy.

FindWindow returning handles of non existant programs

P: n/a
Bob
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0.
What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
_

lpClassName As String, ByVal lpWindowName As String) As Long

Public Function GetHandleByClass(ByVal strTargetProgram As String) As Long

Try

Return FindWindow(strTargetProgram, vbNullString) ' Always returns a large
arbitary number

Catch ex As Exception

MsgBox("Gethandle error " & ex.Message)

End Try

End Function


Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 2005-08-03, Bob <bo*@nowhere.com> wrote:
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0.
What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
_

lpClassName As String, ByVal lpWindowName As String) As Long


This declaration should be:

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

A long is 64-bits in VB.NET.

--
Tom Shelton [MVP]
Nov 21 '05 #2

P: n/a
Bob
Hi Tom, Thanks for that,
I also found
<DllImport("user32.dll")> Public Shared Function _

FindWindow(ByVal strClassName As String, ByVal strWindowName _

As String) As Integer

Which works.

Is there any .net reference for the WINAPI calls? Guess there must be but I
haven't been able to find it. All the examples I have tried have been from
trolling through the help etc.
regards
bob
"Tom Shelton" <ts******@YOUKNOWTHEDRILLcomcast.net> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
On 2005-08-03, Bob <bo*@nowhere.com> wrote:
Hi,
Trying to determine if a program is running or not.
I implemented the example code below but I am getting handles returned
regardless of whether a program exists or not. i.e. You can feed in a
rubbish string for the lpClassName parameter and still get back a long > 0. What am I doing wrong?
thanks
Bob
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal _

lpClassName As String, ByVal lpWindowName As String) As Long


This declaration should be:

Private Declare Auto Function FindWindow Lib "user32" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr

A long is 64-bits in VB.NET.

--
Tom Shelton [MVP]

Nov 21 '05 #3

P: n/a
Hi Bob
Is there any .net reference for the WINAPI calls? Guess there must be but I haven't been able to find it. All the examples I have tried have been from
trolling through the help etc.


Try ApiViewer 2004:

http://www.activevb.de/rubriken/apiv...viewereng.html

It provides declarations of many API functions, constants, and structures in
VB, VB .NET, C# and many more.

For descriptions and samples see API-Guide:

http://www.allapi.net/cgi-bin/redire...place=apiguide

Most samples there are in VB6, but there's some .NET replacement code as
well.

HTH

Roman

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.