0

I use ctypes to call a dll to read the contents of the storage area.But it returns an unsigned char pointer, I want to get the contents of the pointer.How do I do it?

from ctypes import *

c = WinDLL("FT_ET99_API.dll")
hwnd = c_void_p()
c.et_OpenToken(byref(hwnd), c_char_p('53E00FD8'), c_int(1))
c.et_Verify(hwnd, c_int(0), c_char_p('35316D69696C616E'))
f = c.et_Read
f.argtypes = c_void_p, c_int, c_int, POINTER(c_char_p)
f.restype = None
txt = c_char_p()
f(hwnd, 1, 34, byref(txt))
(What should I do next?)

et_Read( 

ET_HANDLE hHandle(in),

WORD offset(in), 

int Len(in), 

unsigned char* pucReadBuf(out) 

) 
Gaurav Sehgal
  • 7,422
  • 2
  • 18
  • 34
M.Mark
  • 63
  • 2
  • 13
  • Dereference the pointer. https://stackoverflow.com/questions/4955198/what-does-dereferencing-a-pointer-mean/4955297#4955297 – quadruplebucky Aug 14 '17 at 07:10
  • »I want to get the contents of the pointer« What do you mean? Do you want to retrieve the type and the size of the data stored or do you want to interface the raw buffer to python? The first is not possible because memory does not carry info about it's contents, the second is: https://stackoverflow.com/questions/18895081 – Henri Menke Aug 14 '17 at 07:13
  • It would be a `char**` if it were meant to allocate the buffer for you and return a pointer to it. As a `char *`, I think it's expecting you to allocate the buffer -- e.g. `txt = create_string_buffer(34)`, which you would pass as `f(hwnd, 1, 34, txt)`. The value would be either `txt.value` (the null terminated substring) or `txt[:]` or `txt.raw` (all 34 bytes). – Eryk Sun Aug 14 '17 at 07:27

1 Answers1

0

I tried another way and it succeeded.I get the contents of the raw buffer.

from ctypes import *

c = WinDLL("FT_ET99_API.dll")
hwnd = c_void_p()
c.et_OpenToken(byref(hwnd), c_char_p('53E00FD8'), c_int(1))
c.et_Verify(hwnd, c_int(0), c_char_p('35316D69696C616E'))
outData = create_string_buffer(34)
c.et_Read(hwnd, 1, 34, outData)
print outData.value(my aim)
M.Mark
  • 63
  • 2
  • 13