特定的VBA调用DLL

时间:2014-03-13 15:20:49

标签: dll

我正在使用一个名为Coolprops的程序将制冷剂属性放入电子表格中。它包含一个由this代码编写的DLL。幸运的是,它带有一个模块,已经设置了对DLL的调用。我没有任何问题让程序开箱即用。

我需要做的是访问位于代码中第1042行的函数。我尝试复制和修改其中一个开箱即用的调用:

Private Declare Function Props_private Lib "K:\Refrigeration\Coolprop\CoolProp.dll" Alias "_Props@32" (ByVal Output As String, ByVal Name1 As Long, ByVal Value1 As Double, ByVal Name2 As Long, ByVal Value2 As Double, ByVal Ref As String) As Double

对此:

Private Declare Function set_ref_state Lib "K:\Refrigeration\Coolprop\CoolProp.dll" Alias "set_reference_stateP" (ByVal fluid As String, ByVal ref_state As string)

但是当我在我的代码中调用它时:

Public Function Props(ByVal Output As String, ByVal Name1 As String, ByVal Value1 As Double,     ByVal Name2 As String, ByVal Value2 As Double, ByVal fluid As String) As Double

Dim refstate

refstate = set_ref_state("Ammonia", "ASHRAE")

Dim errstring As String
Dim N1, N2 As Integer
Dim Props_temp As Double
Dim L As Long


Props_temp = Props_private(Output, Asc(Left(Name1, 1)), Value1, Asc(Left(Name2, 1)), Value2, fluid)
If Abs(Props_temp > 100000000) Then
    'Make a null-terminated string that is plenty big
    errstring = String(2000, vbNullChar)
    'Get the error string
    L = get_global_param_string_private("errstring", errstring)
    'Display it
    Props = errstring
Else
    Props = Props_temp
End If

End Function

Props功能坏了。

我的猜测是我在这里缺少一些简单的东西。

1 个答案:

答案 0 :(得分:1)

不确定您是否仍然坚持这一点,但您需要更改别名。在https://github.com/ibell/coolprop/blob/master/wrappers/Excel/exports.txt查看DLL的导出。它应该是_set_reference_stateS@8

Windows的乐趣啊。

将来,堆栈溢出可能不是您寻求帮助的最佳选择 - 请查看coolprop.org上的所有帮助链接