UDF > WinAPIEx > System > DLLLib >


_WinAPI_GetModuleHandle

Obtient le handle d'un module sp�cifi�

#include <WinAPISys.au3>
_WinAPI_GetModuleHandle ( $sModuleName )

Param�tre

$sModuleName Les noms d'un module Win32 (un fichier .dll ou .exe).
Si l'extension du nom de fichier est omis, par d�faut, l'extension .dll est ajout�e.
La cha�ne de nom de fichier peut inclure un caract�re point (.) pour indiquer que le nom du module n'a pas d'extension.
La cha�ne n'a pas � sp�cifier un chemin.
Le nom est compar� (ind�pendamment de la casse) aux noms des modules actuellement mapp�s dans l'espace d'adressage du processus appelant.
Si ce param�tre est le mot-cl� Null alors la fonction retourne le handle de fichier utilis� pour cr�er le processus appelant.

Valeur de retour

Succ�s: Retourne le handle du module sp�cifi�
�chec: Retourne 0, appelez _WinAPI_GetLastError() pour obtenir des informations suppl�mentaires sur l'erreur

Voir aussi

Consultez GetModuleHandle dans la librairie MSDN.

Exemple

#include <MsgBoxConstants.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

Global $g_hHook, $g_hStub_KeyProc, $g_sBuffer = ""

Example()

Func Example()
    OnAutoItExitRegister("Cleanup")

    Local $hMod

    $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "long", "int;wparam;lparam")
    $hMod = _WinAPI_GetModuleHandle(0)
    $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)

    MsgBox($MB_SYSTEMMODAL, "", "Cliquez sur OK, puis dans notepad tapez..." & _
            @CRLF & @CRLF & "Jon" & @CRLF & "AutoIt" & @CRLF & @CRLF & "Pressez Esc pour arr�ter le script")

    Run("notepad.exe")
    WinWait("[CLASS:Notepad]")
    WinActivate("[CLASS:Notepad]")

    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>Example

Func EvaluateKey($iKeycode)
    If (($iKeycode > 64) And ($iKeycode < 91)) _ ; a - z
            Or (($iKeycode > 96) And ($iKeycode < 123)) _ ; A - Z
            Or (($iKeycode > 47) And ($iKeycode < 58)) Then ; 0 - 9
        $g_sBuffer &= Chr($iKeycode)
        Switch $g_sBuffer
            Case "Jon"
                ToolTip("Que voulez-vous dire?")
            Case "AutoIt"
                ToolTip("AutoIt Rocks")
        EndSwitch
    ElseIf ($iKeycode > 159) And ($iKeycode < 164) Then
        Return
    ElseIf ($iKeycode = 27) Then ; touche Esc
        Exit
    Else
        $g_sBuffer = ""
    EndIf
EndFunc   ;==>EvaluateKey

;===========================================================
; Fonction de rappel
;===========================================================
Func _KeyProc($nCode, $wParam, $lParam)
    Local $tKEYHOOKS
    $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)
    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
    EndIf
    If $wParam = $WM_KEYDOWN Then
        EvaluateKey(DllStructGetData($tKEYHOOKS, "vkCode"))
    Else
        Local $iFlags = DllStructGetData($tKEYHOOKS, "flags")
        Switch $iFlags
            Case $LLKHF_ALTDOWN
                ConsoleWrite("$LLKHF_ALTDOWN" & @CRLF)
            Case $LLKHF_EXTENDED
                ConsoleWrite("$LLKHF_EXTENDED" & @CRLF)
            Case $LLKHF_INJECTED
                ConsoleWrite("$LLKHF_INJECTED" & @CRLF)
            Case $LLKHF_UP
                ConsoleWrite("$LLKHF_UP: scanCode - " & DllStructGetData($tKEYHOOKS, "scanCode") & @TAB & "vkCode - " & DllStructGetData($tKEYHOOKS, "vkCode") & @CRLF)
        EndSwitch
    EndIf
    Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_KeyProc

Func Cleanup()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
EndFunc   ;==>Cleanup