Click to See Complete Forum and Search --> : dll error


jehyun nam
September 13th, 2001, 10:56 PM
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

Cakkie
September 14th, 2001, 01:47 AM
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
slisse@planetinternet.be

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