Hi,
ich weiß, die Frage mit dem Zugriff auf DLL-Funktionen kam schon öfter auf, aber vielleicht hilft mir das hier mal zur Klärung...
Ich will mit AutoIt die USBaccess.dll von Cleware (http://www.cleware.de/) nutzen, damit kann man z.B. die Temperatur von einem USB-Device von Cleware auslesen. Mit C/C++ klappt das Ganze auch einwandfrei, mit AutoIt komm ich da aber auf keinen Nenner. Die Funktionen sind alle in der API.pdf (im Anhang) beschrieben und ich möchte jetzt vorherst nur eine Rückgabe, ob die Funktion aufgerufen werden kann mit AutoIt. Dazu folgender Code:
Spoiler anzeigen
#NoTrayIcon
#include <Array.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
Opt("MustDeclareVars", 0)
main()
Func _ClewareGetTemp($s_dllpath, $s_function, $s_returnval)
Local $h_dll
$h_dll = DllOpen($s_dllpath)
If $h_dll == -1 Then
MsgBox(16, "Error", "Unable to open " & $s_dllpath)
EndIf
DllCall($h_dll, $s_returnval, $s_function)
Select
Case @error == 1
MsgBox(16, "Error", "Unable to use " & $s_dllpath)
Case @error == 2
MsgBox(16, "Error", "Unknown return type of " & $s_function)
Case @error == 3
MsgBox(16, "Error", "Function " & $s_function & " not found in " & $s_dllpath)
EndSelect
DllClose($h_dll)
EndFunc
Func main()
Local Const $S_APPTITLE = "USB Temperature"
Local Const $S_APPVERSION = "1.0"
Local Const $S_DLLPATH = "USBaccess.dll"
Local $a_harddisk, $i_maingui, $i_readtempbt, $a_msg
$i_maingui = GUICreate($S_APPTITLE & " v" & $S_APPVERSION, 640, 480, -1, -1, $WS_BORDER + $WS_SYSMENU + $WS_VISIBLE)
$i_readtempbt = GUICtrlCreateButton("&Read Temperature", 10, 10, 120, 20)
While 1
$a_msg = GUIGetMsg(1)
Select
Case $a_msg[0] == $GUI_EVENT_CLOSE
ExitLoop
Case $a_msg[0] == $i_readtempbt
_ClewareGetTemp($S_DLLPATH, "CUSBaccess CWusb", "none")
EndSelect
WEnd
GUIDelete($i_maingui)
Exit(0)
EndFunc
Normalerweise müsste ich doch jetzt was anderes zurückbekommen als @error... Habs auch mit anderen Funktionen getestet. Liegt es daran, dass die DLL extra für so eine Nutzung gebaut werden muss (bin ned so der experte im umgang mit dlls...) eigentlich müsste eine Nutzung der Funktionen doch möglich sein, wenn sie als public deklariert sind...
Achso, was ich noch gesehen hab ist, dass sie Beispiele in VB dabei haben... Das wäre ansonsten natürlich eine Alternative diese in AutoIt zu übersetzen, allerdings nutzen sie dafür ActiveX-Steuerelemente... (Wie nutzt man denn die?)
Naja, bin mal gespannt auf Antworten.
bernd670: Spoiler gesetzt!