Python Ctypes weird behavior

I am trying to create a bot for an application called Virtual Paradise, and the SDK that is designed to build the bot is compiled into a shared library, so I need to use ctypes.

when i use

import threading
...
from ctypes import CDLL, CFUNCTYPE, c_char_p, c_int, c_void_p
vp = CDLL("libvpsdk.so")
vp.vp_string.restype = c_char_p
vp.vp_int.restype = c_int
...
class bot(threading.Thread):
    def initBot(self):
        ...
        instance = vp.vp_create()
        ...
        EventFunc = CFUNCTYPE(None)
        event_chat_func = EventFunc(self.event_chat)
        vp.vp_event_set(instance, 0, event_chat_func)
        ...
    def event_chat(self):
        print "Hello"
        ...

event_chat is called correctly and prints "Hello"

but when i use this

import threading
import chat
...
from ctypes import CDLL, CFUNCTYPE, c_char_p, c_int, c_void_p
vp = CDLL("libvpsdk.so")
vp.vp_string.restype = c_char_p
vp.vp_int.restype = c_int
...
class bot(threading.Thread):
    def initBot(self):
        ...
        instance = vp.vp_create()
        ...
        chat.VPSDK(vp, instance)
        ...

Chat.py:

from ctypes import CFUNCTYPE
...
class VPSDK:
    def __init__(self, vp, instance):
        EventFunc = CFUNCTYPE(None)
        event_chat_func = EventFunc(self.event_chat)
        vp.vp_event_set(instance, 0, event_chat_func)

    def event_chat(self):
        print "Hello"
        ...

I get an error "Invalid instruction"

What am I doing wrong? I need to use this separate class, otherwise the other parts of my bot will lose functionality.

+1
source share
1 answer

, . . ... 15.16.1.17. Python.

- self.event_chat_func , .

, chat.VPSDK(vp, instance) chat.VPSDK, . , bot , VPSDK .

+3

All Articles