Sign in to follow this  
Followers 0
vatobeto

Can't get GetClassName DLL function to work

7 posts in this topic

Hi.

If any who read this recently helped me, but I didn't answer - apologies: dead DSL modem, just replaced. Back on point. I'm still not completely sure how to use Win32 API DLL calls correctly in AutoIt. Could anyone provide a clue why the following code doesn't work?

The return value for the GetNameClass API function in the AutoIt Wrapper function is always 0, indicating failure. What am I doing wrong?

$AutoExec = @ScriptDir & "\Portable_Micro20.exe";A freeware program
$wndTitle = "SilentNight Micro CD/DVD/ISO/AUDIO Burner version 4.1.2 - Unregistered version"
$ctrlName1 = "Edit1"        ;These 3 gotten with Au3Info tool
$ctrlName2 = "TAdvComboBox1"
$winText = "CD/DVD"

$winHand = WinGetHandle ($wndTitle, $winText)
Dim $TCHARBuffer

$GetClassName = 0x0000e032 ;Gotten with DLL Export Viewer tool

Run($AutoExec, "")
WinWait($wndTitle, $winText)

$CB_Handle = ControlGetHandle($wndTitle, $winText, $ctrlName2)

WinWaitActive($wndTitle, $winText)
_GetClassName($CB_Handle, $TCHARBuffer)
MsgBox(0, "", $TCHARBuffer)

Exit

Func _GetClassName($hwnd, ByRef $buffer)
    local $dll = DllOpen("user32.dll")
    local $ID = DllCall("user32.dll", "int", $GetClassName, "hwnd", $hwnd, "str", $buffer, "int", 32786)
    DllClose($dll)
    If $ID == 0 Then
        MsgBox(0,"Error", "Couldn't make DLL Call.")
        Exit
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

Hi.

If any who read this recently helped me, but I didn't answer - apologies: dead DSL modem, just replaced. Back on point. I'm still not completely sure how to use Win32 API DLL calls correctly in AutoIt. Could anyone provide a clue why the following code doesn't work?

The return value for the GetNameClass API function in the AutoIt Wrapper function is always 0, indicating failure. What am I doing wrong?

$AutoExec = @ScriptDir & "\Portable_Micro20.exe";A freeware program
$wndTitle = "SilentNight Micro CD/DVD/ISO/AUDIO Burner version 4.1.2 - Unregistered version"
$ctrlName1 = "Edit1"    ;These 3 gotten with Au3Info tool
$ctrlName2 = "TAdvComboBox1"
$winText = "CD/DVD"

$winHand = WinGetHandle ($wndTitle, $winText)
Dim $TCHARBuffer

$GetClassName = 0x0000e032;Gotten with DLL Export Viewer tool

Run($AutoExec, "")
WinWait($wndTitle, $winText)

$CB_Handle = ControlGetHandle($wndTitle, $winText, $ctrlName2)

WinWaitActive($wndTitle, $winText)
_GetClassName($CB_Handle, $TCHARBuffer)
MsgBox(0, "", $TCHARBuffer)

Exit

Func _GetClassName($hwnd, ByRef $buffer)
    local $dll = DllOpen("user32.dll")
    local $ID = DllCall("user32.dll", "int", $GetClassName, "hwnd", $hwnd, "str", $buffer, "int", 32786)
    DllClose($dll)
    If $ID == 0 Then
        MsgBox(0,"Error", "Couldn't make DLL Call.")
        Exit
    EndIf
EndFunc
To add a bit more info, here is the MSDN definition of the GetClassName function:

The GetClassName function retrieves the name of the class to which the specified window belongs.

Syntax

int GetClassName(

HWND hWnd,

LPTSTR lpClassName,

int nMaxCount

);

Parameters

hWnd

[in] Handle to the window and, indirectly, the class to which the window belongs.

lpClassName

[out] Pointer to the buffer that is to receive the class name string.

nMaxCount

[in] Specifies the length, in TCHAR, of the buffer pointed to by the lpClassName parameter. The class name string is truncated if it is longer than the buffer and is always null-terminated.

Return Value

If the function succeeds, the return value is the number of TCHAR copied to the specified buffer.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Hope that helps.

V.

Share this post


Link to post
Share on other sites

I don't know the DLL calls very well, and if this is an exercise to learn them, this won't help, but...

I see how to get the control's ClassNameNN without a dll call in the AutoIT script. The following script returns a list of ClassNameNN control IDs from a window. The returned list is a single string with @LF between IDs, the same as WinGetClassList(). You could StringSplit() that list into an array and step through it with ControlGetHandle() until you got a match to the one you were interested in:

#Include <array.au3>

Global $avCtrlList[1] = [0]
$Title = "AutoIt Help"
$Text = ""

$ClassNames = _WinGetClassNameList($Title, $Text)
MsgBox(64, "Test", $ClassNames)


;==================================================
; Function _WinGetClassNameList()
;   Returns a string containing a list of all ClassNameNN control IDs in a window.
;   On success returns all ClassNameNN's in a string delimited by @LF.
;   On failure returns 0 and sets @error.
;==================================================
Func _WinGetClassNameList($sWinTitle = "", $sWinText = "")
    Local $c, $NN, $hCtrl
    ; Get list of classes in the window
    Local $sClassList = WinGetClassList($sWinTitle, $sWinText)
    If @error Then Return SetError(1, 0, 0)
    Local $avClassList = StringSplit($sClassList, @LF)
    ; Try different values of NN
    $sClassList = ""
    For $c = 1 To $avClassList[0]
        $NN = 1
        While 1
            $hCtrl = ControlGetHandle($sWinTitle, $sWinText, $avClassList[$c] & $NN)
            If @error Then
                ExitLoop
            Else
                $sClassList &= $avClassList[$c] & $NN & @LF
                $NN += 1
            EndIf
        WEnd
    Next
    Return $sClassList
EndFunc   ;==>_WinGetClassNameList

:shocked:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

$hwnd = GUICreate("Silly")
Dim $buff
_GetClassName($hwnd,$buff)
ConsoleWrite($buff & @LF)


Func _GetClassName($hwnd,ByRef $buff)
    Local $vBuff = DllStructCreate("char[256]")
    local $aTmp = DllCall("user32.dll", "int","GetClassName", "hwnd", $hwnd, "ptr", DllStructGetPtr($vBuff), "int", DllStructGetSize($vBuff))
    If @error Then Return SetError(1,0,"")
    $buff = DllStructGetData($vBuff,1)
    Return $aTmp[0]
EndFunc


CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map

Share this post


Link to post
Share on other sites

Definitely a searchable answer...

search forum...

+dllcall +getclassname

Lar.

Right you are. I just wasn't sure enough of the syntax of this search tool - I've only seen it one other place. Good, except for that 3-letter lower length limit;

it sort of eliminates certain searches like: "Control ID". I know, use: "ControlID"

V.

Share this post


Link to post
Share on other sites

$hwnd = GUICreate("Silly")
Dim $buff
_GetClassName($hwnd,$buff)
ConsoleWrite($buff & @LF)
Func _GetClassName($hwnd,ByRef $buff)
    Local $vBuff = DllStructCreate("char[256]")
    local $aTmp = DllCall("user32.dll", "int","GetClassName", "hwnd", $hwnd, "ptr", DllStructGetPtr($vBuff), "int", DllStructGetSize($vBuff))
    If @error Then Return SetError(1,0,"")
    $buff = DllStructGetData($vBuff,1)
    Return $aTmp[0]
EndFunc
Muito obrigado! Much thanks - perfect. What other language has forum members as astute as AutoIt? (Self not included)

Share this post


Link to post
Share on other sites

I don't know the DLL calls very well, and if this is an exercise to learn them, this won't help, but...

I see how to get the control's ClassNameNN without a dll call in the AutoIT script. The following script returns a list of ClassNameNN control IDs from a window. The returned list is a single string with @LF between IDs, the same as WinGetClassList(). You could StringSplit() that list into an array and step through it with ControlGetHandle() until you got a match to the one you were interested in:

#Include <array.au3>

Global $avCtrlList[1] = [0]
$Title = "AutoIt Help"
$Text = ""

$ClassNames = _WinGetClassNameList($Title, $Text)
MsgBox(64, "Test", $ClassNames)
;==================================================
; Function _WinGetClassNameList()
;   Returns a string containing a list of all ClassNameNN control IDs in a window.
;   On success returns all ClassNameNN's in a string delimited by @LF.
;   On failure returns 0 and sets @error.
;==================================================
Func _WinGetClassNameList($sWinTitle = "", $sWinText = "")
    Local $c, $NN, $hCtrl
    ; Get list of classes in the window
    Local $sClassList = WinGetClassList($sWinTitle, $sWinText)
    If @error Then Return SetError(1, 0, 0)
    Local $avClassList = StringSplit($sClassList, @LF)
    ; Try different values of NN
    $sClassList = ""
    For $c = 1 To $avClassList[0]
        $NN = 1
        While 1
            $hCtrl = ControlGetHandle($sWinTitle, $sWinText, $avClassList[$c] & $NN)
            If @error Then
                ExitLoop
            Else
                $sClassList &= $avClassList[$c] & $NN & @LF
                $NN += 1
            EndIf
        WEnd
    Next
    Return $sClassList
EndFunc   ;==>_WinGetClassNameList

:shocked:

Thanks. Not exactly what I was looking for, but very instructive not the less. Quite useful in other contexts.

V.

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