1

I have a shared library (DLL) which I am importing to a python script, I am able to call function but I am not able to write to a global variable. I used "memset" by passing address of the global variable, data and size of the variable (4 bytes in this case as that global is an interger) but when I tried reading the global it always shows output as 0(zero). can please someone help me in this. how to set data to a global variable in a shared library using python?

Karthik S
  • 11
  • 1
  • 1
    Possible duplicate of [Python: Sharing global variables between modules and classes therein](http://stackoverflow.com/questions/3338283/python-sharing-global-variables-between-modules-and-classes-therein) – Rao Dec 11 '15 at 01:59
  • 2
    Let's get a lib with a global `int` variable: `open('test.c', 'w').write('__declspec(dllexport) int gvar=0;');` `os.system('cl /LD test.c');` `lib = ctypes.CDLL('test');`. Now set the value to 42: `gvar = ctypes.c_int.in_dll(lib, 'gvar');` `gvar.value = 42`. – Eryk Sun Dec 11 '15 at 13:13

0 Answers0