How does Python assign and retrieve a global dll variable?

Dll written in C

extern int32_T myinput; extern int32_T myoutput; extern void initialize(void); extern void run(void); extern void terminate(void); void run(void) { myoutput = myinput * 2; } 

Python script

 from ctypes import* mydll = cdll.LoadLibrary("C:\\myDLL.dll") mydll.myinput = 10 # Question1 mydll.initialize() mydll.run() print(mydll.myoutput) # Question2 mydll.terminate() 

My expectation

 20 

Actual output

 <_FuncPtr object at 0x00000000023646C8> 

My question

  • How to assign a global variable in a DLL?
  • How to get global variable in DLL?

In short, could you modify my script to conclude 20?

+5
source share

Source: https://habr.com/ru/post/1215891/


All Articles