Re: Accessing integers at certain memory locations
Thomas Heller <theller <at> python.net>
2003-02-05 13:10:51 GMT
"Hanzac Chen" <hanzac <at> hotmail.com> writes:
> Thomas,
>
> hehe, I've learned a lot & I'm sorry for keeping the mind of "C".
Well, a certain mind of "C" is probably needed to use ctypes
.
> I found that I began to like exploring the inner implementation. :)thanks
>
> BTW, I have another problem:
>
> When I want to create a Structure & it have a anonymous Union(or
> Struct), I found it is hard to realize it. Will you implement the
> feature?
>
Anonymous structures or unions are not (yet) supported, and I have
doubts I want to implement them, because there's an easy workaround:
Just fetch a name and use it. I also have the impression from looking
at C header files, that not all compilers support them.
Taking VARIANT as an example, this is how I defined it in the samples
(this definition is neither complete nor correct, but I hope you get
the impression):
class VARIANT(Structure):
class U(Union):
_fields_ = [("bVal", "b"), # VT_UI1
("iVal", "h"), # VT_I2
("lVal", "l"), # VT_I4
("fltVal", "f"), # VT_R4
("dblVal", "d"), # VT_R8
("boolVal", "i"), # VT_BOOL
("scode", "i"), # VT_ERROR
("pdispVal", IDispatchPointer), # VT_DISPATCH
("punkVal", IUnknownPointer), # VT_UNKNOWN
("bstrVal", "i"),
("myBstrVal", "Z"),
("uiVal", "H"), # VT_UI2
("ulVal", "L"), # VT_UI4
("intVal", "i"), # VT_INT
("uintVal", "I"), # VT_UINT
]
_fields_ = [("vt", "h"),
("wReserved1", "h"),
("wReserved2", "h"),
("wReserved3", "h"),
("u", U)]
So, you have to write
v = VARIANT()
v.u.bVal
instead of
v.bVal
You could also use '_' as the name for the anonymous part,
and then write
v._.bVal instead if you prefer.
>
> I am also looking forward to your next version of ctypes.
I'm still fixing a lot of bugs, and writing unittests.
But as I said before, it there is a need for a snapshot
I can create one.
>
> Hanzac
>
Thomas
-------------------------------------------------------
This SF.NET email is sponsored by:
SourceForge Enterprise Edition + IBM + LinuxWorld = Something 2 See!
http://www.vasoftware.com