-2

I have 'C' library returning c_void_p and c_ulong values. How to print the actual data in python?

When I print the c_void_p it prints an integer value 4899550 and c_ulong prints 32.

I am not asking to print the values, it is the actual data I need. How can we retrieve string data from those two ctypes?

Niru
  • 31
  • 5
  • Have you tried ``print``? What problem did you encounter when trying to display the data? Can you please [edit] your question to include a minimal example that we can work with? – MisterMiyagi May 18 '20 at 15:55

1 Answers1

2

Found the way to print the actual data. Say I got these values from the external C library, c_void_p ("buffer" value as integer) and c_ulong ("bufferLength" as integer)

import ctypes

Get the n characters from the memory.

rawData = (ctypes.c_char*bufferLength.value).from_address(buffer.value)

Decode the raw data ascii and ignore any errors

print(rawData.decode(encoding='ascii', errors='ignore')

Thanks to this post: How to read from pointer address in Python?

Community
  • 1
  • 1
Niru
  • 31
  • 5