#cs================================================================================================== Bsp.: Beep( ) Wir werden jetzt die Funktion Beep( ) als DllCall ausführen. Die Funktion verwendet 2 Parameter: Frequenz und Dauer. Wir führen den Aufruf mit 500 Hz über 700 ms aus. Hier die Originalbeschreibung aus der Windows API-Referenz: Declare Function Beep Lib "kernel32" Alias "Beep" (ByVal dwFreq As Long, ByVal dwDuration As Long) As Long · dwFreq Specifies the frequency, in hertz, of the sound. This parameter must be in the range 37 through 32,767 (0x25 through 0x7FFF). · dwDuration Specifies the duration, in milliseconds, of the sound. Die Funktion wird hier in folgender Form dargestellt: "Funktionsname" "DLL" ["Alias-Funktionsname"] ("Parametername", "Parametertyp", ...) Rückgabetyp Der Dll Aufruf in AutoIt erwartet folgende Darstellung: DllCall("DLL", "Rückgabetyp", "Funktionsname" [,"Parametertyp", "Parametername", ...]) Suchen wir uns die notwendigen Angaben zusammen: DLL = "kernel32" Rückgabetyp = "long" Funktionsname = "Beep" (der Alias braucht nur verwendet werden, wenn er vom Funktionsnamen abweicht) Parmetertyp = "long" Parametername = "dwFreq" (500) Parmetertyp = "long" Parametername = "dwDuration" (700) Und so sieht nun der fertige Aufruf aus: #ce MsgBox(0, 'Beispiel', 'Starte Beep') DllCall("kernel32", "long", "Beep", "long", 500, "long", 700) #cs================================================================================================== Bsp.: "Hallo Welt!" Wir wollen per MsgBox den Text "Hallo Welt!" ausgeben. Hier wiederum die Infos aus der Windows API-Referenz: Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long · hWnd Identifies the owner window of the message box to be created. If this parameter is NULL, the message box has no owner window. · lpText Points to a null-terminated string containing the message to be displayed. · lpCaption Points to a null-terminated string used for the dialog box title. If this parameter is NULL, the default title Error is used. · uType Specifies a set of bit flags that determine the contents and behavior of the dialog box. hWnd hier können wir 0 übergeben, da wir die Nachricht allgemein anzeigen lpText hier kommt unser Text rein: "Hallo Welt!" lpCaption das ist der Titel der MsgBox, wir nehmen: "Test" uType wir brauchen nur den OK-Button, das ist die 0 So sieht es fertig aus: #ce MsgBox(0, 'Beispiel', 'Starte MessageBoxA') DllCall("user32", "long", "MessageBoxA", "hwnd", 0, "str", "Hallo Welt!", "str", "Test", "long", 0) #cs Ihr seht in dieser Funktion den Suffix "A" am Funktionsnamen. Für UNICODE wäre also folgender Aufruf zuständig. #ce MsgBox(0, 'Beispiel', 'Starte MessageBoxW') DllCall("user32", "long", "MessageBoxW", "hwnd", 0, "wstr", "Hallo Welt!", "wstr", "Test", "long", 0) #cs ================================================================================================== Bsp.: GetVolumeInformation Nun zu einer Funktion, die uns mehrere Ergebniswerte liefert. Wieder die Beschreibung aus der API-Referenz: Declare Function GetVolumeInformation Lib "kernel32" Alias "GetVolumeInformationW" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long · lpRootPathName Points to a string that contains the root directory of the volume to be described. If this parameter is NULL, the root of the current directory is used. If this parameter is a UNC name, you must follow it with an additional backslash. For example, you would specify \\MyServer\MyShare as \\MyServer\MyShare\. · lpVolumeNameBuffer Points to a buffer that receives the name of the specified volume. · nVolumeNameSize Specifies the length, in characters, of the volume name buffer. This parameter is ignored if the volume name buffer is not supplied. · lpVolumeSerialNumber Points to a variable that receives the volume serial number. This parameter can be NULL if the serial number is not required. · lpMaximumComponentLength Points to a doubleword value that receives the maximum length, in characters, of a filename component supported by the specified file system. A filename component is that portion of a filename between backslashes. The value stored in variable pointed to by *lpMaximumComponentLength is used to indicate that long names are supported by the specified file system. For example, for a FAT file system supporting long names, the function stores the value 255, rather than the previous 8.3 indicator. Long names can also be supported on systems that use the New Technology file system. · lpFileSystemFlags Points to a doubleword that receives flags associated with the specified file system. · lpFileSystemNameBuffer Points to a buffer that receives the name of the file system (such as FAT or NTFS). · nFileSystemNameSize Specifies the length, in characters, of the file system name buffer. This parameter is ignored if the file system name buffer is not supplied. Hier gehts nun richtig zur Sache. :=) In den Parameterbeschreibungen findet ihr fast überall: "Points to ...". Das bedeutet für uns, dass auf einen Pointer verwiesen wird, der zurÜbergabe/Übernahme von Werten benötigt wird. Pointer bedeutet, an dieser Stelle wird nicht eine Variable gespeichert, sondern es wird auf den Speicherort der Variablen verwiesen. Um das mit AutoIt zu realisieren, wird folgendermaßen vorgegangen: - Erstellen einer Struktur des erforderlichen Datentyps "DllStructCreate( )" - wenn notwendig, Werte übergeben an die Struktur "DllStructSetData( )" - im Aufruf wird dann der Datentyp "ptr" genutzt, gefolgt von "DllStructGetPtr($Struktur)" #ce ; das Ziel unserer Abfrage $Vol = 'C:\' ; Erstellen der Struktur zur Übergabe (1 größer als Stringlänge!) $lpRootPathName = DllStructCreate('wchar[' & StringLen($Vol)+1 & ']') ; Füllen der Struktur DllStructSetData($lpRootPathName, 1, $Vol) ; Erstellen der Struktur zur Aufnahme des VolumeNamens $lpVolumeNameBuffer = DllStructCreate('wchar[255]') ; Angabe der Länge des Aufnahmepuffers für VolumeName $nVolumeNameSize = 255 ; Erstellen der Struktur zur Aufnahme der Seriennummer $lpVolumeSerialNumber = DllStructCreate('wchar[255]') ; Erstellen der Struktur zur Aufnahme der max. Komponentenlänge $lpMaximumComponentLength = DllStructCreate('dword') ; Erstellen der Struktur zur Aufnahme der FileSytemFlags $lpFileSystemFlags = DllStructCreate('dword') ; Erstellen der Struktur zur Aufnahme des FileSystemNamens $lpFileSystemNameBuffer = DllStructCreate('wchar[255]') ; Angabe der Länge des Aufnahmepuffers für FileSystemName $nFileSystemNameSize = 255 DllCall("Kernel32", "long", "GetVolumeInformationW", _ 'ptr' , DllStructGetPtr($lpRootPathName), _ 'ptr' , DllStructGetPtr($lpVolumeNameBuffer), _ 'long', $nVolumeNameSize, _ 'ptr' , DllStructGetPtr($lpVolumeSerialNumber), _ 'ptr' , DllStructGetPtr($lpMaximumComponentLength), _ 'ptr' , DllStructGetPtr($lpFileSystemFlags), _ 'ptr' , DllStructGetPtr($lpFileSystemNameBuffer), _ 'long', $nFileSystemNameSize) ; Nach dem DllCall sind die ermittelten Werte in den über die Pointer adressierten Strukturen enthalten. ; Um auf diese Werte zuzugreifen, werden diese mit "DllStructGetData( )" ausgelesen. MsgBox(0, 'Beispiel', "GetVolumeInformationW - Ausgabe in Console") ConsoleWrite('Volume name: ' & DllStructGetData($lpVolumeNameBuffer, 1) & @CRLF) ConsoleWrite('Serial number: ' & DllStructGetData($lpVolumeSerialNumber, 1) & @CRLF) ConsoleWrite('Max. Component Length: ' & DllStructGetData($lpMaximumComponentLength, 1) & @CRLF) ConsoleWrite('File System: ' & DllStructGetData($lpFileSystemNameBuffer, 1) & @CRLF) ConsoleWrite('File System Flags: ' & _checkFSflags(DllStructGetData($lpFileSystemFlags, 1)) & @CRLF) ; Hilfsfunktion zum Prüfen der Flags Func _checkFSflags($flagsum) Local Const $FS_CASE_IS_PRESERVED = 0x2 Local Const $FS_CASE_SENSITIVE = 0x1 Local Const $FS_UNICODE_STORED_ON_DISK = 0x4 Local Const $FS_PERSISTENT_ACLS = 0x8 Local Const $FS_FILE_COMPRESSION = 0x10 Local Const $FS_VOL_IS_COMPRESSED = 0x8000 Local $sFlags = @CRLF If BitAND($flagsum, $FS_CASE_IS_PRESERVED) Then $sFlags &= @TAB & 'FS_CASE_IS_PRESERVED' & @CRLF EndIf If BitAND($flagsum, $FS_CASE_SENSITIVE) Then $sFlags &= @TAB & 'FS_CASE_SENSITIVE' & @CRLF EndIf If BitAND($flagsum, $FS_UNICODE_STORED_ON_DISK) Then $sFlags &= @TAB & 'FS_UNICODE_STORED_ON_DISK' & @CRLF EndIf If BitAND($flagsum, $FS_PERSISTENT_ACLS) Then $sFlags &= @TAB & 'FS_PERSISTENT_ACLS' & @CRLF EndIf If BitAND($flagsum, $FS_FILE_COMPRESSION) Then $sFlags &= @TAB & 'FS_FILE_COMPRESSION' & @CRLF EndIf If BitAND($flagsum, $FS_VOL_IS_COMPRESSED) Then $sFlags &= @TAB & 'FS_VOL_IS_COMPRESSED' & @CRLF EndIf Return $sFlags EndFunc #cs ================================================================================================== Bsp.: GetCursorPos( ) Diese Funktion enthält als Parameter bereits eine Struktur. Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long · lpPoint Points to a POINT structure that receives the screen coordinates of the cursor. Das Vorgehen für uns ist wie im letzten Bsp., die geforderte Struktur erstellen und mit einem Pointer darauf verweisen. Einige Strukturen sind in AutoIt bereits enthalten. Einfach mal nach suchen unter "$tagSTRUKTURNAME". Ansonsten hilft Google: Type POINTAPI x As Long y As Long End Type Das übersetzen wir jetzt nach AutoIt: #ce $tPOINTAPI = DllStructCreate("long x;long y") DllCall("user32", "long", "GetCursorPos", "ptr", DllStructGetPtr($tPOINTAPI)) ; die Werte aus der Struktur auslesen MsgBox(0, 'Beispiel', "GetCursorPos - Ausgabe in Console") ConsoleWrite('x:' & DllStructGetData($tPOINTAPI, 1) & @CRLF) ConsoleWrite('y:' & DllStructGetData($tPOINTAPI, 2) & @CRLF)