Skip to content
Advertisement

Access a global pointer in C from python using ctypes

I know that if I have a global variable (let’s say a double called N) I can read it using:

JavaScript

but what if my variable is a pointer? How can I read the contents of the pointer in to a python list?

To be clearer, N is declared in the following way in the shared library:

JavaScript

Advertisement

Answer

Given this (Windows) DLL source:

JavaScript

You can access these exported global variables with:

JavaScript

To get a list, if you know the size:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement