gpt4 book ai didi

python - CTYPES:可能使用太多参数调用过程(超出 92 个字节)

转载 作者:行者123 更新时间:2023-12-02 15:53:37 26 4
gpt4 key购买 nike

我有一个 dll

__declspec(dllexport) int __cdecl wrp_ANN_sel_HDGT(int steps,
double in_TNH[], double in_TNL[], double in_pamb[], double in_Tamb[], double in_CPD[],
double in_T3[], double in_Tex[], double in_IGV[], double in_Dpin[], double in_Dpout[],
double in_LHV[], double in_RH[], short in_model, double in_pamb_ref, double in_Dpin_ref,
double in_Dpout_ref, double in_LHV_ref, double in_RH_ref, double out_Tfire[], double out_T39[], double out_Power[], char *RuleDllPath)

我定义了argtypes

# Specify the parameter and return types
hllDll.wrp_ANN_sel_HDGT.argtypes = [ctypes.POINTER(ctypes.c_int),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N), ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_short), ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double), ctypes.POINTER(ctypes.c_double),
ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N),
ctypes.POINTER(ctypes.c_double * N),
ctypes.c_char_p]

我用数据填充了指针

RuleDllPath = ctypes.c_char_p(b'ANN_sel_HDGT_win32')


in_TNH = (ctypes.c_double * N)()
in_TNL = (ctypes.c_double * N)()
in_pamb = (ctypes.c_double * N)()
in_Tamb = (ctypes.c_double * N)()
in_CPD = (ctypes.c_double * N)()
in_T3 = (ctypes.c_double * N)()
in_Tex = (ctypes.c_double * N)()
in_IGV = (ctypes.c_double * N)()
in_Dpin = (ctypes.c_double * N)()
in_Dpout = (ctypes.c_double * N)()
in_LHV = (ctypes.c_double * N)()
in_RH = (ctypes.c_double * N)()



for i in range(0, N):
in_TNH[i] = float(SpeedH[i])
in_TNL[i] = float(SpeedL[i])
in_pamb[i] = float(Pamb[i])
in_Tamb[i] = float(Tamb[i])
in_CPD[i] = float(CPD[i])
in_T3[i] = float(CTD[i])
in_Tex[i] = float(TEX[i])
in_IGV[i] = float(IGV[i])
in_Dpin[i] = float(Inloss[i])
in_Dpout[i] = float(OutLoss[i])
in_LHV[i] = float(LHV[i])
in_RH[i] = float(ro[i])

然后我打电话

# Call function
a = wrp_ANN_sel_HDGT(ctypes.byref(steps), ctypes.byref(in_TNH), ctypes.byref(in_TNL), ctypes.byref(in_pamb),
ctypes.byref(in_Tamb), ctypes.byref(in_CPD), ctypes.byref(in_T3), ctypes.byref(in_Tex),
ctypes.byref(in_IGV), ctypes.byref(in_Dpin), ctypes.byref(in_Dpout), ctypes.byref(in_LHV),
ctypes.byref(in_RH),
ctypes.byref(in_model),
ctypes.byref(in_pamb_ref),
ctypes.byref(in_Dpin_ref), ctypes.byref(in_Dpout_ref), ctypes.byref(in_LHV_ref), ctypes.byref(in_RH_ref),
ctypes.byref(out_Tfire), ctypes.byref(out_T39), ctypes.byref(out_Power), (RuleDllPath))

我得到了

ValueError: Procedure probably called with too many arguments (92 bytes in excess)

最佳答案

如果您使用windll.LoadLibrary,请尝试使用CDLL

来自网络:“该函数的调用约定是 x86 cdecl,但您使用的是 x86 stdcall 约定 (WinDLL)。”如果您使用 32 位 Python,则可能是约定问题。

对于这样的 C 函数:

__declspec(dllexport) int __cdecl wrp_testchar(int steps, double in_data[], char* in_char )

Python 代码必须是:

N = 2

from ctypes import *

# Load the library
hllDll = CDLL("testchar.dll") wrp_testchar = hllDll.wrp_testchar

# Specify the parameter and return types
hllDll.wrp_testchar.argtypes = [POINTER(c_int), POINTER(c_double * N), c_char_p]

# Next, set the return types...
hllDll.wrp_testchar.restype = c_int
steps = (c_int)(2)

in_data = (c_double * N)()
in_data[0] = float(1)
in_data[1] = float(1)

in_char = (c_char_p)(b'Helloworld')

a = int(0)

# Call function
a = wrp_testchar(byref(steps), byref(in_data), in_char)

关于python - CTYPES:可能使用太多参数调用过程(超出 92 个字节),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41760830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com