Files
2025-10-14 09:52:32 +09:00

64 lines
2.4 KiB
Python

import ctypes
import platform
def load_dll():
"""auto-detect the correct library"""
if (platform.system() == "Windows") or (platform.system()[0:6] == "CYGWIN"):
if ctypes.sizeof(ctypes.c_voidp) == 4:
# WINDOWS 32bit
t32api = ctypes.CDLL("./t32api.dll")
# alternative using windows DLL search order:
# t32api = ctypes.cdll.t32api
else:
# WINDOWS 64bit
t32api = ctypes.CDLL("./t32api64.dll")
# alternative using windows DLL search order:
# t32api = ctypes.cdll.t32api64
elif platform.system() == "Darwin":
# Mac OS X
t32api = ctypes.CDLL("./t32api.dylib")
else:
if ctypes.sizeof(ctypes.c_voidp) == 4:
# Linux 32bit
t32api = ctypes.CDLL("./t32api.so")
else:
# Linux 64bit
t32api = ctypes.CDLL("./t32api64.so")
return t32api
def declare_fnc_args_ret(t32api):
"""declare the argument- and return-types of the functions used in this file"""
t32api.T32_Config.argtypes = [ctypes.POINTER(ctypes.c_char)]
t32api.T32_Config.restype = ctypes.c_int
t32api.T32_Init.argtypes = []
t32api.T32_Init.restype = ctypes.c_int
t32api.T32_Attach.argtypes = [ctypes.c_int]
t32api.T32_Attach.restype = ctypes.c_int
t32api.T32_Ping.argtypes = []
t32api.T32_Ping.restype = ctypes.c_int
t32api.T32_Exit.argtypes = []
t32api.T32_Exit.restype = ctypes.c_int
t32api.T32_ExecuteCommand.argtypes = [ctypes.POINTER(ctypes.c_char), ctypes.POINTER(ctypes.c_char), ctypes.c_uint32]
t32api.T32_ExecuteCommand.restype = ctypes.c_int
t32api.T32_ExecuteFunction.argtypes = [
ctypes.POINTER(ctypes.c_char),
ctypes.POINTER(ctypes.c_char),
ctypes.c_uint32,
ctypes.POINTER(ctypes.c_uint32),
]
t32api.T32_ExecuteFunction.restype = ctypes.c_int
# channel related
t32api.T32_RequestChannelNetAssist.argtypes = [ctypes.POINTER(ctypes.c_void_p)]
t32api.T32_RequestChannelNetAssist.restype = None
t32api.T32_RequestChannelNetTcp.argtypes = [ctypes.POINTER(ctypes.c_void_p)]
t32api.T32_RequestChannelNetTcp.restype = None
t32api.T32_ReleaseChannel.argtypes = [ctypes.POINTER(ctypes.c_void_p)]
t32api.T32_ReleaseChannel.restype = None
t32api.T32_SetChannel.argtypes = [ctypes.c_void_p]
t32api.T32_SetChannel.restype = None