Get the address of the ctypes object

I have a buffer like:

bufstr = ctypes.create_string_buffer("Test", 32) 

How do I get the address of this buffer? i.e. displayed if I do:

 print bufstr 

as:

 <ctypes.c_char_Array_32 object at 0x042ACAD0> 

I know that I can pass it using byref (), for example; but what if I just want to get this address (other than slicing this line!)?

Thanks!

+4
source share
2 answers

Use ctypes. addressof .

 ctypes.addressof(bufstr) 
+5
source

I believe:

 ctypes.addressof(bufstr) 

must do it. Note that the address specified in toString is for the Python object, not C memory.

+3
source

Source: https://habr.com/ru/post/1342572/


All Articles