How to access to C global variable structure by Python and ctype [duplicate]

▼魔方 西西 提交于 2019-12-04 21:18:00

You need to use the in_dll method to access a global variable.

This works:

import ctypes

class Inp(ctypes.Structure):
   _fields_ = [('In1', ctypes.c_float),
               ('In2', ctypes.c_float)]

class Out(ctypes.Structure):
   _fields_ = [('Out1', ctypes.c_float)]

myLib = ctypes.CDLL('./SimpleTest.so')

SimpleTest_initialize = myLib.SimpleTest_initialize
SimpleTest_initialize()

SimpleTest_Y = Out.in_dll(myLib, 'SimpleTest_Y')

print SimpleTest_Y.Out1
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!