Ich hab mal wieder eine schöne ctypes Aufgabe.
Ich hab in LabView ein einfaches Beispiel erstellt. Die addition von zwei Zahlen. "Zahl1" als Eingabewert, "Zahl2" als Festwert und ein "Ergebnis" als Ausgabewert. Aus diesem Programm hab ich dann eine dll erstellt, wo ich auch "Zahl1" und "Ergebnis" in der dll veröffentlich hab. Fein nach Anleitung. Ich denke das sollte alles richtig sein.
Nun möchte ich an die dll einen Wert für "Zahl1" übergeben und "Ergebnis" wieder auslesen.
Hier einmal die Anleitung von der NI Seite für C++:
Code: Alles auswählen
To dynamically load the DLL, you must define function types and function
pointers for all the functions in the DLL. You then load the DLL into
memory when necessary using the LoadLibrary function. After loading the
DLL, use the GetProcAddress function to obtain the addresses of the
functions. After you call all the functions, unload the DLL using the
FreeLibrary function.
Aus dem ctypes Tutorial hab ich zwei Ansätze erstellt, wobei der 2.Ansatz wahrscheinlich besser ist wegen:"you must define function types and function pointers for all the functions in the DLL"
Ansatz1:
Code: Alles auswählen
from ctypes import *
dll = cdll.LoadLibrary("addition.dll")
Funk = getattr(dll, "Addition")
print Funk
Code: Alles auswählen
from ctypes import *
dll = cdll.LoadLibrary("addition.dll")
class struct_frozen(Structure):
_fields_ = [("Zahl1", c_int),
("Ergebnis", c_int)]
FrozenTable=POINTER(struct_frozen)
opt_flag=FrozenTable.in_dll(dll, "Addition")
Also meine Funktion heißt Addition. Das läuft so weit auch schon und ich bekomme keine Fehlermeldung zurück. Aber wie komme ich jetzt an das Ergebnis bzw kann ein Wert in Zahl1 an die dll übergeben???????
Kann mir da jemand weiterhelfen?
Danke
mfg
HarryPython