Sign in to follow this  
Followers 0
MiserableLife

[Solved]DllCall problem

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You need to use null as the window class, not an empty string. Try passing 0 as the first string parameter.

If all you need is the handle though, why not just use WinGetHandle?

Edited by Richard Robertson

Share this post


Link to post
Share on other sites

So i changed it to

$i = DllCall("user32.dll","HWND","FindWindow","str",0,"str",$title)

but still returns 0x00000000.

And the reason for not using WinGetHandle, is becuase i wanted to learn how to use dllcall.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Ah. Try changing the parameter type to "ptr" and passing 0.

Share this post


Link to post
Share on other sites

Yeah!!! It worked!!!

Thank you!!

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@@ very detailed!!!

Thank you too.

Share this post


Link to post
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
Sign in to follow this  
Followers 0