开发者

Get the address of a ctypes object

开发者 https://www.devze.com 2023-02-15 08:58 出处:网络
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:

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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消