Fortran dll的Python ctypes调用:OSError:异常:访问冲突读取0x00000000

2024-04-27 01:00:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在python中调用fortran dll,但遇到了OSerror:exception:access violation reading 0x00000000。在

.dll函数调用应具有以下属性: double FDIR(double *x,const double *a, int32_t *na, int32_t *k, double *h, double *x1,const int32_t *relparam, int32_t *m, int32_t *profile, int32_t *nlines, int32_t *nrefer, double *deltaX)。另外,我有一个成功调用.dll的labview脚本,因此我知道问题出在python脚本中。在

下面是我到目前为止的代码

from ctypes import * 
import numpy as np
#Define Variables
x = np.arange(0, 5.52602+0.197358, 0.197358)
a = [2.65477,0.859621,0.0177231,0.0001,0,4.15638,0,0,
     2.75715,-0.00442,
     0,1,0, 
     0,1,0] 
na = len(a)
k = 0
h = 0
x1 = 0
relparams = [0,0,0,0,0,0,0,0]
m = 8
profile = 1
nlines = 1
nref = 0
deltax = 0
#Conversions
a = np.asarray(a)
relparams = np.asarray(relparams, dtype = np.int32)
#Call Dll
fit_dll = cdll.LoadLibrary("mydll.dll")
#Loop dll
for x_ in x:
    fit_dll.FDIR(c_double(x_), 
                    a.ctypes.data_as(POINTER(c_double)), 
                    c_int32(na), 
                    c_int32(k),
                    c_double(h), 
                    c_double(x1), 
                    relparams.ctypes.data_as(POINTER(c_int)),
                    c_int32(m),
                    c_int32(profile),
                    c_int32(nlines),
                    c_int32(nref),
                    c_double(deltax))
    print (result)

这里有什么明显的问题吗?如有任何帮助/建议,我们将不胜感激!在

更新:谢谢你的帮助,阿巴纳特!我为函数添加了argtypes和restype。并添加了其他变量的指针。现在不是OSerror:exception:accessinvolution读取0x00000000。我得到ValueError:调用过程时参数不足(缺少48个字节)或调用约定错误。有什么想法吗?在

^{pr2}$

Tags: asnpexceptionprofilectypesdlldoublex1