我目前正在尝试将vb6 32位COM包装器更新为.Net(最终从64位应用程序中调出进程)。以下代码似乎可以解决我为_dSpeedOfSound赋值的问题,即gOutput填充了3个返回值。但是,当我尝试访问属性dSpeedOfSound(或三者中的任何一个)时,我收到以下错误:"类型的异常' System.ExecutionEngineException'被扔了#34;即使我在设置了_dSpeedOfSound之后立即进入并且从即时窗口尝试了?dSpeedofSound,也是如此。我假设我至少缺少一个重要的步骤,但我是COM的新手,不知道如何从这里继续。怀疑我没有正确处理数组。任何帮助表示赞赏,相关代码如下:
<ComVisible(True)> _
<Guid("C3516C29-5A8C-4D09-8869-6DAF597EC123")> _
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface INF_AGA8
Sub NF_AGA8()
...
Readonly Property dSpeedOfSound() As Double
...
End Interface
ComVisible(True)> _
<Guid("04385623-B6F2-44CF-AD82-C1FEE5EACB42")> _
<ClassInterface(ClassInterfaceType.None)> _
<ProgId("NFLOMIC.NF_AGA8")> _
Public Class NF_AGA8
Implements INF_AGA8
...
Private _dSpeedOfSound As Double
...
Public ReadOnly Property dSpeedOfSound() As Double Implements INF_AGA8.dSpeedOfSound
Get
Return _dSpeedOfSound
End Get
End Property
...
Private gInput(0 To 11) As Double
Private gOutput(0 To 2) As Double
...
<DllImport("C:\temp\TSS DLL\aga8.dll)> _
Public Shared Function aga8_g(ByRef ain As Double, ByRef aout As Double, ByRef iErrCode As Integer,
ByRef sErrMess As String, ByRef iEFlags As Long) As Integer
End Function
...
Call aga8_g(gInput(0), gOutput(0), iErrCode, sLomicErrMessage, iErrFlags)
_dMolarDensity = gOutput(0)
_dCompressibility = gOutput(1)
_dSpeedOfSound = gOutput(2)
...
以下内容来自工作的vb6代码(使用选项base 1):
Private Declare Sub aga8_g Lib "d:\psoft\lomic\bin\aga8.dll" (ain1 As Any, aout1 As Any, iErrCode As Integer, sErrMess As String, iEFlags As Long)
...
Call aga8_g(aInput(1), aOutput(1), iErrCode, sLomicErrMessage, iErrFlags)