Call .net 6 from VBA, problem idl file

New Contributor

I have created a TLB file from IDL with three functions in .Net 6. When i call the functions form excel VBA two of the functions are called correctly but the third one is calling the wrong function. My Code is below:

The IDL file

library COMThermo
{
// TLib : mscorlib.dll : {BED7F4EA-1A96-11D2-8F08-00A0C9A6186D}
importlib("mscorlib.tlb");
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");

// Forward declare all types defined in this typelib
interface ICOMThermo;

[
odl,
uuid(B221E497-C862-4C40-B4E6-5D79E7AB28D5),
version(1.0),
oleautomation,
custom(B10B0742-6D84-415D-894C-798ED2D76C1D, "COMThermo.ICOMThermo")

]
interface ICOMThermo : IUnknown {
[id(0x60020000)]
HRESULT _stdcall TestCritT([out, retval] double* pRetVal);
[id(0x60020001)]
HRESULT _stdcall StreamEnthalpyReal(
[in] VARIANT comps,
[in] VARIANT X,
[in] double T,
[in] double P,
[in] long method,
[out, retval] double* pRetVal);
[id(0x60020002)]
HRESULT _stdcall LiqEnthalpyReal(
[in] VARIANT comps,
[in] VARIANT X,
[in] double T,
[in] double P,
[in] long method,
[out, retval] double* pRetVal);
/* HRESULT _stdcall DistillationPoint( etc


the VBA Code;

Dim test As New COMThermo.COMThermo

Function Test1()
Test1 = test.TestCritT()
End Function
Function StreamEnthalpy(comp As Range, Xfractions As Range, T As Double, P As Double, Method As Integer) As Double
Dim Names() As String
Dim x() As Double

No = comp.Cells.Count
ReDim Names(No - 1)
ReDim x(No - 1)

For i = 1 To No
Names(i - 1) = comp(i).Value
x(i - 1) = Xfractions(i).Value
Next

StreamEnthalpy = test.StreamEnthalpyReal(Names, x, T + 273.15, P, Method)

'End Function
End Function

Function LiqEnthalpy(comp As Range, Xfractions As Range, T As Double, P As Double, Method As Integer) As Double
Dim Names() As String
Dim x() As Double

No = comp.Cells.Count
ReDim Names(No - 1)
ReDim x(No - 1)

For i = 1 To No
Names(i - 1) = comp(i).Value
x(i - 1) = Xfractions(i).Value
Next

LiqEnthalpy = test.LiqEnthalpyReal(Names, x, T + 273.15, P, Method)

End Function

I cant see whay that is happening (im not so familiar with IDL)

0 Replies