It's hard for me to understand the difference between LP_ * pointers (like LP_c_char) and * _p (like c_char_p) in Python types. Is there any documentation that distinguishes them?
Little has I read about * _p pointers, it says they are better (in some vague way), but when I try to use them as structural fields, I get strange behavior. For example, I can create a structure with an LP_c_char pointer field:
import ctypes char = ctypes.c_char('a') class LP_Struct(ctypes.Structure): _fields_ = [('ptr', ctypes.POINTER(ctypes.c_char))] struct = LP_Struct(ctypes.pointer(char)) print type(struct.ptr)
And the resulting pointer:
<class 'ctypes.LP_c_char'>
But when I create a structure with a c_char_p pointer field:
class Struct_p(ctypes.Structure): _fields_ = [('ptr', ctypes.c_char_p)] p = ctypes.pointer(char) struct = Struct_p(ctypes.cast(p, ctypes.c_char_p)) print type(struct.ptr)
received field "ptr"
<type 'str'>
In other words, the pointer was dereferenced somewhere in the process.
source share