On Mar 18, 5:48 pm, Nobody <nob...@nowhere.com> wrote:
> On Fri, 18 Mar 2011 10:34:35 -0700, Wanderer wrote:
> > I'm observing some strange behavior with ctypes. I created this test
> > code to try to figure out what I'm doing wrong creating pointers to
> > structures.
>
> What makes you think that you're doing anything wrong.
>
> Note that the hex number shown when printing a ctypes object is the
> object's ID (as per the id() function). This is typically the address of
> the Python object. It is not the address of the structured data nor (in
> the case of a ctypes pointer) the value of the pointer.
>
> If you want to see the actual value of a ctypes pointer, cast it to
> c_void_p then examine the .value field, e.g.:
>
>         p = pointer(x)
>         print hex(cast(p, c_void_p).value)

In the real program the pointer to the structure is passed to the DLL.
The DLL has functions CreateCameraSettingsStruct and
ReleaseCameraSettingsStruct. Once I call CreateCameraSettingStruct, I
can't delete the pointer without crashing Python. Calling
ReleaseCameraSettingStruct doesn't help. The result is the program
crashes on exit during the class destruction. I was trying to figure
out why ReleaseCameraSettingStruct doesn't release the pointer so
Python can close the program. I was checking to see what happened
before and after ReleaseCameraSettingStruct and saw this. But it
happens even if I don't run ReleaseCameraSettingStruct.

Thanks for the reply, but I'm still not sure I understand. Why should
Object1 be at address1 and Object2 be at address2 and the next moment
Object2 is at address1 and Object1 is at address2? I'll try casting
them to see what the value is before and after calling
ReleaseCameraSettingStruct.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to