I have a buffer like:
bufstr = ctypes.create_string_buffer("Test", 32)
How I obtain the address of that buffer? i.e. the one displayed if I do:
print bufstr
like:
<ctypes.c_char_Array_32 object at 0x042ACAD0>
I know I can pass it with byref(), for example; but what if I just want to get that address (aside from slicing that string!)?
Thanks!
ctypes is a foreign function library for Python. It provides C compatible data types, and allows calling functions in DLLs or shared libraries. It can be used to wrap these libraries in pure Python.
ctypes is the de facto standard library for interfacing with C/C++ from CPython, and it provides not only full access to the native C interface of most major operating systems (e.g., kernel32 on Windows, or libc on *nix), but also provides support for loading and interfacing with dynamic libraries, such as DLLs or ...
A cubit is an ancient unit based on the forearm length from the middle fingertip to the elbow bottom. Cubits of various lengths were employed in many parts of the world in antiquity, during the Middle Ages and as recently as Early Modern Times.
Use ctypes.addressof.
ctypes.addressof(bufstr)
I believe:
ctypes.addressof(bufstr)
should do it. Note that the address mentioned in toString is for the Python object, not the C memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With