Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

pass array of types to com server

ancientcoder
Beginner
548 Views

We have a VB dotnet app using a com server we are building. We need to pass in an array of types to a method. The types contain arrays of doubles.

We have succeeded in passing in one type using this code:

Dim

ar_LmdaPar(2) As Double '3 elements

Dim ar_MuPar(1) As Double '2 elements

Dim ar_CpPar(3) As Double '4 elements

Dim mw As Double

ar_LmdaPar(0) = 0.1

ar_LmdaPar(1) = 0.2

ar_LmdaPar(2) = 0.3

ar_MuPar(0) = 0.11

ar_MuPar(1) = 0.22

ar_CpPar(0) = 0.1111

ar_CpPar(1) = 0.2222

ar_CpPar(2) = 0.3333

ar_CpPar(3) = 0.4444

mw = 0.7777

Dim oneGas As AdderLib.GasKind

oneGas =

New AdderLib.GasKind

oneGas.GasKind(ar_LmdaPar, ar_MuPar, ar_CpPar, mw)

But when I try to create an array of the type GasKind using the code below and load it I get the error

"Object reference not set to an instance of an object"

dim

gasArray() As AdderLib.GasKind

gasArray(0) =

New AdderLib.GasKind --- this line generates the error

gasArray(0).GasKind(ar_LmdaPar, ar_MuPar, ar_CpPar, mw)

The arrays all are fine as well as the double mw

I tried creating the instance then assigning it to the first element of the array like
gasArray(0) = oneGas

and still got the same error

Here is the fortran generateed by the wizard:

module

IGasKind_Methods

! These routines get implemented by the user

interface

function IGasKind_GasKind( ObjectData ,&

LmdaPar,&

MuPar,&

CpPar,&

Mw)

result (hresult)

use GasKind_Types

type(GasKind_InstanceData) ObjectData

!dec$ attributes reference :: ObjectData

REAL(8), intent(inout) :: LmdaPar

DIMENSION LmdaPar(1:3)

REAL(8), intent(inout) :: MuPar

DIMENSION MuPar(1:2)

REAL(8), intent(inout) :: CpPar

DIMENSION CpPar(1:4)

REAL(8), intent(inout) :: Mw

integer(long) hresult

end function

end interface

! Local definition of SysStringLen

interface

pure integer*4 function SysStringLen_Local(bstr);

!dec$ attributes default, stdcall, decorate, alias : 'SysStringLen' :: SysStringLen_Local

use ifwinty

integer(int_ptr_kind()), intent(in) :: bstr

!dec$ attributes value :: bstr

end function SysStringLen_Local

end interface

contains

! Wrapper functions called from the Vtbl

function $IGasKind_GasKind( pInterface ,&

LmdaPar ,&

MuPar ,&

CpPar ,&

Mw )

result (hresult)

!dec$ attributes stdcall :: $IGasKind_GasKind

use GasKind_Types

use ifcom

implicit none

type (IGasKind_Ptr) pInterface

!dec$ attributes reference :: pInterface

integer(INT_PTR_KIND()), intent(inout) :: LmdaPar

!dec$ attributes reference :: LmdaPar

integer(INT_PTR_KIND()), intent(inout) :: MuPar

!dec$ attributes reference :: MuPar

integer(INT_PTR_KIND()), intent(inout) :: CpPar

!dec$ attributes reference :: CpPar

REAL(8), intent(inout) :: Mw

!dec$ attributes reference :: Mw

integer(long) hresult

integer i

REAL(8) f$LmdaPar(1:3)

pointer(ptr$LmdaPar, f$LmdaPar)

integer(INT_PTR_KIND()) sa$LmdaPar

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

integer dims$LmdaPar

integer lb$LmdaPar(1)

integer ub$LmdaPar(1)

integer nb$LmdaPar(1)

!DEC$ ENDIF

REAL(8) f$MuPar(1:2)

pointer(ptr$MuPar, f$MuPar)

integer(INT_PTR_KIND()) sa$MuPar

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

integer dims$MuPar

integer lb$MuPar(1)

integer ub$MuPar(1)

integer nb$MuPar(1)

!DEC$ ENDIF

REAL(8) f$CpPar(1:4)

pointer(ptr$CpPar, f$CpPar)

integer(INT_PTR_KIND()) sa$CpPar

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

integer dims$CpPar

integer lb$CpPar(1)

integer ub$CpPar(1)

integer nb$CpPar(1)

!DEC$ ENDIF

sa$LmdaPar = NULL

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

lb$LmdaPar = 0

ub$LmdaPar = 0

nb$LmdaPar = (/3/)

!DEC$ ENDIF

sa$MuPar = NULL

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

lb$MuPar = 0

ub$MuPar = 0

nb$MuPar = (/2/)

!DEC$ ENDIF

sa$CpPar = NULL

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

lb$CpPar = 0

ub$CpPar = 0

nb$CpPar = (/4/)

!DEC$ ENDIF

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

dims$LmdaPar = SafeArrayGetDim(LmdaPar)

if (dims$LmdaPar /= 1) then

hresult = E_INVALIDARG

goto 9999

end if

hresult = SafeArrayGetLBound(LmdaPar, 1, lb$LmdaPar(1))

hresult = SafeArrayGetUBound(LmdaPar, 1, ub$LmdaPar(1))

if (nb$LmdaPar(1) /= (ub$LmdaPar(1) - lb$LmdaPar(1) + 1)) then

hresult = E_INVALIDARG

goto 9999

end if

!DEC$ ENDIF

hresult = SafeArrayAccessData(LmdaPar, ptr$LmdaPar)

if (hresult < 0) goto 9999

sa$LmdaPar = LmdaPar

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

dims$MuPar = SafeArrayGetDim(MuPar)

if (dims$MuPar /= 1) then

hresult = E_INVALIDARG

goto 9999

end if

hresult = SafeArrayGetLBound(MuPar, 1, lb$MuPar(1))

hresult = SafeArrayGetUBound(MuPar, 1, ub$MuPar(1))

if (nb$MuPar(1) /= (ub$MuPar (1) - lb$MuPar(1) + 1)) then

hresult = E_INVALIDARG

goto 9999

end if

!DEC$ ENDIF

hresult = SafeArrayAccessData(MuPar, ptr$MuPar)

if (hresult < 0) goto 9999

sa$MuPar = MuPar

!DEC$ IF .NOT. DEFINED(NOCHECK_ARRAY_)

dims$CpPar = SafeArrayGetDim(CpPar)

if (dims$CpPar /= 1) then

hresult = E_INVALIDARG

goto 9999

end if

hresult = SafeArrayGetLBound(CpPar, 1, lb$CpPar(1))

hresult = SafeArrayGetUBound(CpPar, 1, ub$CpPar(1))

if (nb$CpPar(1) /= (ub$CpPar(1) - lb$CpPar(1) + 1)) then

hresult = E_INVALIDARG

goto 9999

end if

!DEC$ ENDIF

hresult = SafeArrayAccessData(CpPar, ptr$CpPar)

if (hresult < 0) goto 9999

sa$CpPar = CpPar

hresult = IGasKind_GasKind(pInterface % pInternalData % pInstanceData ,&

f$LmdaPar ,&

f$MuPar ,&

f$CpPar ,&

Mw )

if (hresult < 0) goto 9999

9999 continue ! Cleanup code

if (sa$LmdaPar /= NULL) i = SafeArrayUnaccessData(sa$LmdaPar)

if (sa$MuPar /= NULL) i = SafeArrayUnaccessData(sa$MuPar)

if (sa$CpPar /= NULL) i = SafeArrayUnaccessData(sa$CpPar)

end function

end module

I can't seem to pass in an array of these types. We have this same code working using un-managed code but really need to have a com server.

Thanks in advance!

0 Kudos
1 Reply
ancientcoder
Beginner
548 Views

Please ignore this post or remove it. I must have been off my meds yesterday.

I was trying to have the com server create objects to be passed back to the server.

I should have been creating arrays of structures in VB and pass those to the com server instead.

Sorry to waste your time

0 Kudos
Reply