我试图为第三方C DLL编写一个Python包装器。在
函数WolaInit
初始化库并返回用于后续函数调用的句柄。在
import ctypes
# Load WOLA DLL into memory.
wolaDLL = ctypes.WinDLL("wola.dll")
# Function prototypes
WolaInit = wolaDLL.WolaInit
WolaInit.restype = ctypes.c_ulong
WolaInit.argtypes = [
ctypes.c_int, # La
ctypes.c_int, # Ls
ctypes.c_int, # R
ctypes.c_int, # N
ctypes.c_int] # stacking
WolaGetStacking = wolaDLL.WolaGetStacking
WolaGetStacking.restype = ctypes.c_int
WolaGetStacking.argtypes = [ctypes.c_ulong]
# Parameters
La = 128
Ls = 64
R = 32
N = 8
stacking = 0
# Initialize
wolaHandle = WolaInit(La, Ls, R, N, stacking)
print('Handle: ' + hex(wolaHandle))
# Test if library was initialized
stackingVal = WolaGetStacking(wolaHandle)
但是,当使用返回的句柄时,会发生访问冲突(访问冲突的地址对应于句柄值加上额外的偏移量)。在
^{pr2}$访问冲突的原因是什么?如何解决?在
句柄通常作为指针实现。在64位系统上,指针是64位的。在Windows上,
c_ulong
是32位。我想你是在截断句柄,但是没有看到函数原型,这只是一个理论。c_void_p
可能是更适合句柄的类型。在相关问题 更多 >
编程相关推荐