CALLDLL |
Appel DLL |
---|---|
Liberty BASIC |
Syntaxe
CALLDLL #handle, "function", param1 as type1 [, param2 as type2 ], RETURN AS returnType |
Paramètres
Nom | Description |
---|---|
#handle | Ce paramètre permet d'indiquer le Handle étant donné au DLL lorsqu'il est ouvert avec l'instruction OPEN. |
function | Ce paramètre permet d'indiquer le nom de la fonction, enfermer entre guillemet. |
param1 as type1 [, param2 as type2 ] | Ce paramètre permet d'indiquer la liste de paramètre requise par la fonction API. |
returnType | Ce paramètre permet d'indiquer la valeur de retour de la fonction API. |
Description
Cette commande permet d'appeler un API du système d'exploitation Windows.
Exemple
Voici un exemple permettant de faire clignoter les lumières du clavier (Caps Lock, Num Lock, Scroll Lock) au nombre de 10 fois chacun leurs tours (aussi connu sous le nom de «Keyboard Dancing LED Light Trick») :
- KEYEVENTFKEYUP = 2
- KEYEVENTFEXTENDEDKEY = 1
- vbKeyCapital = 20
- vbKeyNumLock = 144
- VKSCROLL = 145
-
- open "kernel32.dll" for dll as #kernel32
- open "user32.dll" for dll as #user32
-
- For J = 0 To 10
- For I = 0 To 2
- Select Case I
- Case 0
- calldll #user32, "MapVirtualKeyA", vbKeyCapital As Long, 0 As Long, result As Long
- Attr = result
- Mask = (KEYEVENTFEXTENDEDKEY Or 0)
- calldll #user32, "keybd_event", vbKeyCapital As Long, Attr As Long, Mask As Long, 0 as Long, result As void
-
- calldll #user32, "MapVirtualKeyA", vbKeyCapital As Long, 0 As Long, result As Long
- Attr = result
- Mask = KEYEVENTFEXTENDEDKEY Or KEYEVENTFKEYUP
- calldll #user32, "keybd_event", vbKeyCapital As Long, Attr As Long, Mask As Long, 0 As Long, result As Void
- Case 1
- calldll #user32, "MapVirtualKeyA", vbKeyNumLock As Long, 0 As Long, result As Long
- Attr = result
- Mask = KEYEVENTFEXTENDEDKEY Or 0
- calldll #user32, "keybd_event", vbKeyNumLock As Long, Attr As Long, Mask As Long, 0 as Long, result As void
-
- calldll #user32, "MapVirtualKeyA", vbKeyNumLock As Long, 0 As Long, result As Long
- Attr = result
- Mask = KEYEVENTFEXTENDEDKEY Or KEYEVENTFKEYUP
- calldll #user32, "keybd_event", vbKeyNumLock As Long, Attr As Long, Mask As Long, 0 As Long, result As Void
- Case 2
- calldll #user32, "MapVirtualKeyA", VKSCROLL As Long, 0 As Long, result As Long
- Attr = result
- Mask = KEYEVENTFEXTENDEDKEY Or 0
- calldll #user32, "keybd_event", VKSCROLL As Long, Attr As Long, Mask As Long, 0 As Long, result As Void
-
- calldll #user32, "MapVirtualKeyA", VKSCROLL As Long, 0 As Long, result As Long
- Attr = result
- Mask = KEYEVENTFEXTENDEDKEY Or KEYEVENTFKEYUP
- calldll #user32, "keybd_event", VKSCROLL As Long, Attr As Long, Mask As Long, 0 As Long, result As Void
- End Select
- calldll #kernel32, "Sleep", 250 As Long, Result As Long
- Next I
- Next J
-
- close #kernel32
- close #user32
N.B.: Pour cet exemple, vous pouvez consulter les API de Visual Basic (keybd_event, MapVirtualKeyA, Sleep) pour en savoir plus.
Voir également
Langage de programmation - Visual Basic pour Windows - API de Windows
Dernière mise à jour : Vendredi, le 21 juin 2013