Hallo Autoit3'ler!
Ich bin an einer geraumen zeit an einem Keybinder für GTA San Andreas Multiplayer Mod (SA-MP.com) dran und bräuchte von euch Hilfe im Thema "DllCall"
Damit ihr mein Problem versteht und auch nachvollziehen könnt erklär ich euch kurz warum ich dieses Problem habe:
Damals wo ich ein Script mit einer anderen API.dll angefangen habe, gab es dazu auch gute beispiele in Autoit, jedoch ist es nun so das die API.dll von einem anderen Entwickler der den "betrieb" der .dll eingestellt hat, nun auch nicht mehr funktioniert. (Wegen Update's und Version Prüfungen innerhalb der dll)
Das war / ist das alte script mit der Anderen API.dll:
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$dll = DllOpen("API.dll")
[/autoit] [autoit][/autoit] [autoit]$hModule = DllCall($dll, "UINT", "LoadLibrary", "str", "API.dll")
[/autoit] [autoit][/autoit] [autoit]Global $tickets = 0
[/autoit] [autoit][/autoit] [autoit]Global $username = InputBox("Username","Target ( Username ) Eingeben!")
Global $zeitinterval = InputBox("zeitinterval","Zeit in MS warten auf neue 'BEFEHLR': ")
Global $sperre = InputBox("Sperre","Ab wieviel soll der keybinder aufhören ? ( Zahl eingabe ) ")
Global $BinderAktiv = 0
HotKeySet ( "+!c" , "KeyAktive" ) ;shift+alt+C
HotKeySet ( "+!v" , "CloseProgramm" ) ;shift+alt+V
#Region ### START Koda GUI section ### Form=D:\Source - Programme\Keybinder\Log.kxf
$Log = GUICreate("~", 701, 326, 559, 367)
GUISetBkColor(0xA0A0A4)
$log_file = GUICtrlCreateEdit("", 8, 70, 685, 249, $ES_AUTOVSCROLL+$WS_VSCROLL)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x008000)
GUICtrlSetBkColor(-1, 0x000000)
$id_change = GUICtrlCreateButton("UserID Ändern", 388, 21, 111, 32)
GUICtrlSetCursor (-1, 0)
$intervalchange = GUICtrlCreateButton("Zeit Interval Ändern", 245, 21, 126, 32)
GUICtrlSetCursor (-1, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
CloseProgramm()
Case $id_change
$username = InputBox("Username","Ziel Benutzername ( Username ) Eingeben!")
Case $intervalchange
$zeitinterval = InputBox("$zeitinterval","Zeitspanne in ms")
EndSwitch
If $BinderAktiv == 1 Then
[/autoit] [autoit][/autoit] [autoit]$data = GetPlayerData()
$PlayerID = GetPlayerIdByName($username)
SendChat("/su " & $PlayerID & " 1 BV")
SendChat("/arrest " & $PlayerID & " 1 10000")
$tickets += 1
$cashresult = $tickets * 5000
WriteDebugLog(@HOUR & ":" & @MIN & ":" & @SEC & "- /su " & $PlayerID & " 1 BV | /arrest " & $PlayerID & " 1 10000 | Int: " & $zeitinterval & " | VERB: " & $tickets & " | CASH:" & $cashresult )
Sleep($zeitinterval)
If $tickets == $sperre Then
$BinderAktiv = 0
$cashresult = $tickets * 5000
WriteDebugLog("Script gestoppt :: " & $tickets & " Vebrechen erreicht! ~ Cash result: " & $cashresult)
AddChatMessage(0x00FFFF, "Script gestoppt :: " & $tickets & " Vebrechen erreicht! ~ Cash result: " & $cashresult)
SoundPlay(@WindowsDir & "\media\tada.wav", 1)
EndIf
EndIf
WEnd
Func WriteDebugLog($Textt)
GUICtrlSetData ($log_file, $Textt & @CRLF,1)
EndFunc
Func KeyAktive()
If $BinderAktiv == 0 Then
$BinderAktiv = 1
$tickets = 0
AddChatMessage(0x00FFFF, " ~~~~ Script Aktiviert ~~~~")
WriteDebugLog(" ~~~~ Script Aktiviert ~~~~")
Else
$BinderAktiv = 0
AddChatMessage(0xFFFF00, " ~~~~ Script Deaktiviert ~~~~")
WriteDebugLog(" ~~~~ Script Deaktiviert ~~~~")
$cashresult = $tickets*5000
WriteDebugLog("Script abgrebrochen :: " & $tickets & " Vebrechen erreicht! ~ Cash result: " & $cashresult)
AddChatMessage(0x00FFFF, "Script abgrebrochen :: " & $tickets & " Vebrechen erreicht! ~ Cash result: " & $cashresult)
EndIf
EndFunc
Func CloseProgramm()
DllClose($dll)
Exit
EndFunc
; API Functionen
Func GetOnlinePlayers()
$ret = DllCall($dll, "int:cdecl", _
"API_GetOnlinePlayers")
Return $ret[0]
EndFunc
Func GetPlayerIdByName($name)
$ret = DllCall($dll, "int:cdecl", _
"API_GetPlayerIdByName", _
"str", $name)
Return $ret[0]
EndFunc
Func GetPlayerPingByName($name)
$ret = DllCall($dll, "int:cdecl", _
"API_GetPlayerPingByName", _
"str", $name)
Return $ret[0]
EndFunc
Func GetPlayerData()
$ret = DllCall($dll, "int:cdecl", _
"API_GetPlayerData")
Return $ret[0]
EndFunc
Func GetPlayerPing()
$ret = DllCall($dll, "int:cdecl", _
"API_GetPlayerPing")
Return $ret[0]
EndFunc
Func AddChatMessage($Color, $Text)
$ret = DllCall($dll, "int:cdecl", _
"API_AddChatMessage", _
"int", $Color, _
"str", $Text)
Return $ret[0]
EndFunc
Func SendChat($Text)
$ret = DllCall($dll, "int:cdecl", _
"API_SendChat", _
"str", $Text)
Return $ret[0]
EndFunc
Dieses Script hat auch wunderbar funktioniert.
Nun gibt es die API von http://www.gta-api.de/ | Github: https://github.com/Slider1338/GTA-API
Damit habe ich das problem die DLL Aufzurufen bzw Funktionen so aufrufen das sie funktionieren.
Das ist mein Aktuelles Script in Autoit3:
Spoiler anzeigen
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Misc.au3>
#include <GuiButton.au3>
#include <EditConstants.au3>
#include <Array.au3>
#include <GuiEdit.au3>
OnAutoItExitRegister("OnAutoItExit")
[/autoit] [autoit][/autoit] [autoit]$dll = DllOpen("API.dll")
$hModule = DllCall($dll, "UINT", "LoadLibrary", "str", "API.dll")
$debug = GUICreate("debug", 598, 420, -1, -1)
$log = GUICtrlCreateEdit("", 0, 0, 598, 420, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY), 0)
GUISetState(@SW_SHOW)
AdlibRegister("CheckData", 1500)
[/autoit] [autoit][/autoit] [autoit]While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func CheckData()
WriteToLog("ServerName: " & GetServerName())
EndFunc
Func WriteToLog($str)
_GUICtrlEdit_InsertText($log, $str & @CRLF)
EndFunc;==>WriteToLog($str)
Func GetServerName()
$ret = DllCall($dll, "int:cdecl", _
"GetServerName")
Return $ret[0]
EndFunc;==>GetServerName()
Func OnAutoItExit()
$logFile = @ScriptDir & '\log.txt'
FileOpen($logFile)
FileWrite($logFile, GUICtrlRead($log))
FileClose($logFile)
EndFunc;==>OnAutoItExit()
Für diese API von gta-api.de gibt es aktuell nur Beispiele in AutoHotkey (siehe github oder gta-api.de)
Meine fragen lauten also,
Wie kann ich die DLL Aufrufen so das sie auch "geladen" wird?
Wie kann ich die DLL Funktionen aufrufen? da meine Aktuelle GetServerName Funktion nur eine 0 ausgibt:
Func GetServerName()
$ret = DllCall($hModule, "int:cdecl", _
"GetServerName")
Return $ret
EndFunc;==>GetServerName()
Unter anderem verstehe ich DllCall allgemein mäßig leider nicht
ich weiß das ich mit
DllCall ( "dll", "return type", "function" [, type1, param1 [, type n, param n]] )
[/autoit]
Mit der DLL kommunizieren kann, jedoch weiß ich nicht wie man auf den return type : int:cdecl kommt.
str = string? oder nicht?
Ich bedanke mich ganz herzlich schon mal im Voraus!!
LG, Florian.