Python ctypes ValueError - 参数太多了?

时间:2013-08-19 22:18:02

标签: python dll ctypes

我正在尝试使用ctypes访问自定义DLL。此DLL中有多个函数,除了此特定函数之外的所有函数在使用WinDLL调用过程调用时都有效。

我创建了一个单独的Python函数,它基本上包含了

s = ctypes.WinDLL(r'MyDLL.dll')

def setupOptions(window_area, MinimumRunTime, IGU_Flag, InnerPaneStopFlag,
                     mass_1, x_GlassFail_1, x_WinFail_1,
                     mass_2=0, x_GlassFail_2=0, x_WinFail_2=0, x_gap=0,
                     MaxSteps=10000, MaxNumCycles=2, supp_coeff=0.40528, 
                     FailVelocityFactor=1.0, P_atm=14.7,
                     time_step=0.01, z=0.2, InitialStaticLoad=0.0, 
                     x_initial_1=0.0, Initial_Velocity_1=0.0,
                     x_initial_2=0.0, Initial_Velocity_2=0.0):

# Flag identifying whether the window is an IGU or not
apiIGUFlag = c_long(IGU_Flag)
apiInnerPaneStopFlag = c_long(InnerPaneStopFlag) 

# Percentage of critical damping
z = c_double(z)

# Timestep (this can be increased - didn't spend the time to calculate it)
time_step = c_double(time_step)

# Initial Conditions
InitialStaticLoad = c_double(InitialStaticLoad)
x_initial_1 = c_double(x_initial_1)
Initial_Velocity_1 = c_double(Initial_Velocity_1)
x_initial_2 = c_double(x_initial_2)
Initial_Velocity_2 = c_double(Initial_Velocity_2)

# Failure Values
x_GlassFail_1 = c_double(x_GlassFail_1)
x_WinFail_1 = c_double(x_WinFail_1)
x_GlassFail_2 = c_double(x_GlassFail_2)
x_WinFail_2 = c_double(x_WinFail_2)

# Environment parameters
P_atm = c_double(P_atm)
FailVelocityFactor = c_double(FailVelocityFactor)
supp_coeff = c_double(supp_coeff)

# Other Parameters
window_area = c_double(window_area)
x_gap = c_double(x_gap)

# Model Parameters
apiMaxSteps = c_long(MaxSteps)
apiMaxNumCycles = c_long(MaxNumCycles)

mass_1 = c_double(mass_1)
mass_2 = c_double(mass_2)

MinimumRunTime = c_double(MinimumRunTime)

return s.api_SetupWindowOptions(apiIGUFlag, apiInnerPaneStopFlag, z, time_step, InitialStaticLoad, apiMaxSteps,
                                       apiMaxNumCycles, x_initial_1, Initial_Velocity_1, mass_1, x_GlassFail_1,
                                       x_WinFail_1, x_initial_2, Initial_Velocity_2, mass_2, x_GlassFail_2,
                                       x_WinFail_2, x_gap, window_area, supp_coeff, P_atm, FailVelocityFactor, MinimumRunTime)

这是一个名为:

的函数
area = 2040.0
xgap = 0.5
mass1 = 51.26
mass2 = 51.26
xGlassFail1 = 0.970
xGlassFail2 = 0.750
xWinFail1 = 0.970
xWinFail2 = 9.18
IGUFLAG = 1
minruntime = 52.0
ret = setupOptions(area, minruntime, IGUFLAG, IGUFLAG, mass1, xGlassFail1, xWinFail1, mass2, xGlassFail2, xWinFail2, xgap)

运行代码时出现此错误:

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

就像我说的,我在这个DLL中调用了其他几个函数而没有任何问题。我尝试使用CDLL并导致问题(160字节短)。任何帮助都会受到赞赏,因为我已经看过这一切,根本无法看到问题所在。

此处还有来自C ++头文件的函数调用:

MyDLL_API long _stdcall api_SetupWindowOptions(long nIsIGU, long nInnerPaneStopCriteriaOnly, double dCritDampingPercent, double dTimeStep, double dStaticLoad, long nMaxSteps, long nMaxNumCycles,
                                               double dInitialDisplacementInnerPane, double dInitialVelocityInnerPane, double dMassInnerPane,
                                               double dGlassFailDeflInnerPane, double dWinFailDeflInnerPane, double dInitialDisplacementOuterPane, double dInitialVelocityOuterPane,
                                               double dMassOuterPane, double dGlassFailDeflOuterPane, double dWinFailDeflOuterPane, double dGapSize, double dWindowArea,
                                               double dSupportCoefficient, double dAtmPressure, double dFailVelocityFactor, double dMinimumRuntime);

0 个答案:

没有答案