Jump to content

[Solved]DllCall problem


Recommended Posts

I've been walking around the autoit forum and i found a nice tutorial from monoceres link.

and when i read to page 6, I couldn't get the "FindWindow" function working....(msdn said the function will return the handle)

Can someone tell me what went wrong?

$title = "autoit"
$gui = GUICreate($title)
GUISetState(@SW_SHOW)

$i = DllCall("user32.dll","HWND","FindWindow","str","","str",$title)
IF @error Then msgbox(0,'',@error)
;~ $i = WinGetHandle ("autoit")
    
IF $gui = $i[0] Then
    msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $i[0])
Else
    msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $i[0])
EndIf
Edited by MiserableLife
Link to comment
Share on other sites

@@ I found that it is working with a class param filled.

$title = "autoit"
$gui = GUICreate($title)
GUISetState(@SW_SHOW)

$i = DllCall("user32.dll","HWND","FindWindow","str","AutoIt v3 GUI","str",$title)
IF @error Then msgbox(0,'',@error)
;~ $i = WinGetHandle ("autoit")
    
IF $gui = $i[0] Then
    msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $i[0])
Else
    msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $i[0])
EndIf

Now... my question is .... how to i put a NULL in to the param?

Link to comment
Share on other sites

$sTitle = "autoit"
$sClass = "AutoIt v3 GUI"
$gui = GUICreate($sTitle)
GUISetState(@SW_SHOW)

$hWnd = __WinAPI_FindWindow($sClass, $sTitle)
IF @error Then msgbox(0,'',@error)
    
IF $gui = $hWnd Then
    msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $hWnd)
Else
    msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $hWnd)
EndIf

$hWnd = __WinAPI_FindWindow(0, $sTitle)
IF @error Then msgbox(0,'',@error)
    
IF $gui = $hWnd Then
    msgbox(0,'','They Match' & @CRLF & $gui & @CRLF & $hWnd)
Else
    msgbox(0,'','They do not Match'& @CRLF & $gui & @CRLF & $hWnd)
EndIf

Func __WinAPI_FindWindow($vClass, $sName)
    Local $sType, $aResult
    
    If IsString($vClass) Then
        $sType = "str"
    Else
        $sType = "ptr"
    EndIf
    
    $aResult = DllCall("user32.dll", "hwnd", "FindWindow", $sType, $vClass, "str", $sName)
    If @error Then Return SetError(1, 0, 0)
    Return SetError($aResult[0] = 0, 0, $aResult[0])
EndFunc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...