我正在尝试使用ctypes在Python 2.7中加载DLL.DLL是使用Fortran编写的,并且有多个子例程.我能够成功设置几个导出的函数,long并将double指针作为参数.
import ctypes as C
import numpy as np
dll = C.windll.LoadLibrary('C:\\Temp\\program.dll')
_cp_from_t = getattr(dll, "CP_FROM_T")
_cp_from_t.restype = C.c_double
_cp_from_t.argtypes = [C.POINTER(C.c_longdouble),
np.ctypeslib.ndpointer(C.c_longdouble)]
# Mixture Rgas function
_mix_r = getattr(dll, "MIX_R")
_mix_r.restype = C.c_double
_mix_r.argtypes = [np.ctypeslib.ndpointer(dtype=C.c_longdouble)]
def cp_from_t(composition, temp):
""" Calculates Cp in BTU/lb/R given a fuel composition and temperature.
:param composition: numpy array containing fuel composition
:param temp: temperature of fuel
:return: Cp
:rtype : float
"""
return _cp_from_t(C.byref(C.c_double(temp)), composition)
def mix_r(composition):
"""Return …Run Code Online (Sandbox Code Playgroud) 我有一个用C ++编写的库,并使用Visual Studio 2010编译为DLL。DLL具有多个导出函数。使用可以从Excel访问导出的功能Declare Function。
我正在尝试在程序中实现一项新功能,该功能需要C ++部分中的嵌套结构,然后才能从VBA中进行访问。C ++代码如下所示。
第一结构
struct Parameter {
double value;
char* label;
char* description;
char* units;
};
Run Code Online (Sandbox Code Playgroud)
第二结构
此结构用于构建另一个结构,如下所示:
struct Output {
Parameter field_1;
Parameter field_2;
Parameter field_3;
};
Run Code Online (Sandbox Code Playgroud)
我正在考虑通过VBA访问结构的几种方法。其中之一来自void此类功能。
void Function1(Output* output_function1);
Run Code Online (Sandbox Code Playgroud)
另一个是返回Output结构的函数,例如这样。
Output Function2();
Run Code Online (Sandbox Code Playgroud)
此时,上面两个函数的内部无关紧要。我已经验证了这两种实现都可以在C ++代码中正常工作。
我无法使用Function1或从VBA访问这两个结构Function2。
我在VBA中声明了两种自定义类型。
Type Parameter
Value as Double
Label as String
Description as String
Units as String
End Type
Type Output
Field1 as Parameter
Field2 as Parameter …Run Code Online (Sandbox Code Playgroud)