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

how can i create a two dimension safearray?

史_建鑫
Beginner
548 Views

I want to create a two dimension safearray. But the third parameter of the  function SafeArrayCreate(vt, cDims, ab) defined in the oleaut32.f90 is a variable of TYPE(SA_BOUNDS). here is the define:

[fortran]

    INTEGER(INT_PTR_KIND()) FUNCTION SafeArrayCreate(vt, cDims, ab)
!DEC$IF DEFINED(_X86_)
!DEC$ ATTRIBUTES DEFAULT, STDCALL, ALIAS : '_SafeArrayCreate@12' :: SafeArrayCreate
!DEC$ELSE
!DEC$ ATTRIBUTES DEFAULT, STDCALL, ALIAS : 'SafeArrayCreate' :: SafeArrayCreate
!DEC$ENDIF
          use ifwinty
          INTEGER*4,     INTENT(IN)           :: vt
          !DEC$ ATTRIBUTES VALUE              :: vt
          INTEGER*4,     INTENT(IN)           :: cDims
          !DEC$ ATTRIBUTES VALUE              :: cDims
          TYPE(SA_BOUNDS), INTENT(IN)         :: ab
          !DEC$ ATTRIBUTES REFERENCE          :: ab
    END FUNCTION SafeArrayCreate

[/fortran]

and here is the define of the SA_BOUNDS int the ifwinty.f90

[fortran]

          TYPE SA_BOUNDS
            SEQUENCE
                INTEGER*4       extent
                INTEGER*4   lbound
          END TYPE SA_BOUNDS

[/fortran]

in the SafeArrayCreate, ab is a variable of TYPE(SA_BOUNDS), not a pointer. however, in the msdn, the third parameter of SafeArrayCreate is a pointer, so i  can define a array of SAFEARRRAYBOUND , and pass the address to the third parameter to define a multidimension safearray.

[cpp]

SAFEARRAY * SafeArrayCreate(   VARTYPE vt,   unsigned int cDims,
  SAFEARRRAYBOUND FAR* rgsabound );

[/cpp]

Can anybody help me how to define a multidimension safearray?

thankyou!

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
548 Views

Declare the interface with

[fortran]
...
TYPE(SA_BOUNDS), INTENT(IN)         :: ab(dDims)
!DEC$ ATTRIBUTES REFERENCE          :: ab 
...
[/fortran]

Jim Dempsey

0 Kudos
史_建鑫
Beginner
548 Views

So, you mean the interface in the oleaut32.f90 is wrong? Another question, Do you have some reference for me to write fortran COM program?

the book is scarce, Thank you!

0 Kudos
jimdempseyatthecove
Honored Contributor III
548 Views

I had a type-o, i had dDims, not cDims

If that interface were used to call a Fortran subroutine (your are not)
.AND.
if cDims were .gt. 1

The yes, it would have been in error.

You are calling a C routine Both declarations would work

The original interface would work for that (assuming SEQUENCE use and your array elements are adjacent in memory)

Jim Dempsey

0 Kudos
Reply