[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

URGENT-Problems with FindWindow API function

In my code I need to retrieve the handle to an explorer window if it's running. The Window name is "C:\Test"

I used FindWindow and it worked great. Here is my code:

Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

 ptrRet = FindWindow(vbNullString, "C:\Test")
       
       
        If ptrRet.ToInt32 > 0 Then
           
            MsgBox("Window found")
        Else
            MsgBox("Window not found")
        End If
        If ptrRet.ToInt32 = 0 Then
            Dim temp As Int32 = Marshal.GetLastWin32Error()
            Dim errMsg As String = New Win32Exception(Marshal.GetLastWin32Error()).Message
            MsgBox("ERROR: " & temp & " - " & errMsg)
        End If

I ran this program on Windows XP and it was fine, but when I tried running it on Windows XP Embedded, FindWindow started returning 0

and the error I retrive is Error 5 - Access Denied

I was wondering if there is an equivalent of FindWindow that I could use instead?
0
YZlat
Asked:
YZlat
  • 3
  • 2
1 Solution
 
AlexFMCommented:
Try to declare lpClassName parameter as IntPtr and pass IntPtr.Zero to the function.
0
 
YZlatAuthor Commented:
Alex, that didn't help - same result
0
 
AlexFMCommented:
Interesting that FindWindow API description for WinCE doesn't  say that lpClassName can be NULL. Return to string parameter and try to provide class name.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
YZlatAuthor Commented:
yes, class name can be null. And it works on Windows Xp. The problem occurs on Windows XP Embedded
0
 
YZlatAuthor Commented:
Problem resolved - on Windows XP Embedded it does not show the full path in the title bar, and that's why it couldn't find the window since I was passing the function full title bar. I changed the settings in Folder Options and it worked
0
 
PAQ_ManCommented:
Closed, 500 points refunded.
PAQ_Man
Community Support Moderator
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now