Ich greife mit Python auf eine Dll (testapi.dll) zu und nutze dabei ctypes, das klappt auch alles soweit ganz gut, nur möchte ich jetzt eine Funktion in der Dll nutzen, die eine Union als Übergabewert verlangt nutzen und genau daran scheitere ich. Mache ich da irgendeinen (oder mehrere) Fenkfehler? Anbei folgt die Funktion auf die ich zugreifen möchte, die Union-Beschreibung, und ein Beispiel eines fehlgeschlagenen Versuchs das Problem zu lösen. (Weiß nicht ob das relevant ist, aber ich nutze ctypes-0.6.3 und Python 2.2.1 das muss auch leider so bleiben) Wäre toll wenn ihr mir dabei weiterhelfen könntet.
Die Funktion sieht so aus:
Code: Alles auswählen
bool ReadObject(TAsap3Hdl hdl, TModulHdl module,
const char *ObjectName, TFormat format,
TObjectValue * value);
Die Union beschreibt sich laut api wie folgt:
typedef union {
TValueType type;
struct {
TValueType type;
double value;
} value;
struct {
TValueType type;
short dimension;
double* axis;
} axis;
struct {
TValueType type;
short len;
char* ascii;
} ascii;
struct {
TValueType type;
short dimension;
double* axis;
double* values;
} curve;
struct {
TValueType type;
short xDimension;
short yDimension;
double* xAxis;
double* yAxis;
double* values;
} map;
} TObjectValue;
typedef enum {
VALUE = 0,
CURVE = 1,
MAP = 2,
AXIS = 3,
ASCII = 4
} TValueType;
Code: Alles auswählen
>>> class value(Structure):
... _fields_=[
... ("ValueType", c_int),("value", c_double)]
...
>>> class tcov(Union):
... _fields_=[("ValueType", c_int),("value", value)]
...
>>> co_val=tcov()
>>> windll.testapi.ReadObject(b, a, "channel1", 1, byref(co_val))
1 <- die Funktion antwortet brav mit einem True
>>> print co_val.value.value