CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: dll error

  1. #1
    Join Date
    Sep 2001
    Posts
    1

    dll error

    code :

    Private Sub f_findwindow()
    Dim hwnd1
    hwnd1 = findwindow("windowname", "")
    w_setfocus
    End Sub
    Private Sub w_setfocus()
    Dim rtn As Long
    Dim hwnd1
    rtn = setfocus(hwnd1.hwnd)
    End Sub

    module :
    Public Declare Function findwindow Lib "user32" Alias "findwindowa" _
    (ByVal lpclassname As String, ByVal lpwindowname As String) As Long

    Public Declare Function setfocus Lib "user32" (ByVal hwnd As Long) As Long

    occur '453' runtime error
    help me


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: dll error

    The setfocus function cannot be called from within a form, because it will call the setfocus method of the form. What you can do is change the declaration of the API into

    public Declare Function SF Alias "SetFocus" Lib "user32" (byval hwnd as Long) as Long



    and call SF instead of SetFocus
    Another mistake is that you declare the hwnd1 twice. This will result in hwnd1 always having the value 0 when you come in the other procedure. Place the declaration in the general declaration section of the form.

    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured