!  df.f90 
!
!  FUNCTIONS/SUBROUTINES exported from df.dll:
!  df - 
! Expose subroutine df to users of this DLL
  !
  !DEC$ ATTRIBUTES REFERENCE :: VBArray
  ! Set the attributes needed for compatibility with VB.NET.  VB always uses STDCALL.
  !
SUBROUTINE DF1( VBArray)
  ! Set the attributes needed for compatibility with VB.NET.  VB always uses STDCALL.
  !
  !dec$ attributes dllexport, stdcall, reference, alias : "DF1" :: dF1
  use ifcom ! Declare SafeArray and BSTR interfaces
   
 USE, INTRINSIC :: ISO_C_BINDING
  implicit none
  integer(int_ptr_kind()), intent(inout) :: VBArray  !Pointer to a SafeArray structure  
  ! Array in which we will keep track of array bounds
  type bounds_type
    integer lb  ! Lower Bound
    integer ub  ! Upper Bound
  end type bounds_type
   
  integer(C_INTPTR_T) :: dptr
  type(c_ptr) cptr;
  integer nbounds  ! Number of bounds
  type(bounds_type), allocatable :: bounds(:)
  integer, allocatable :: indexes(:)  ! Array to hold current element indexes
  integer :: i, iRes, length
  REAL(8),PARAMETER :: PI  = 4 * atan (1.0_8)
  character(len=12) :: strd
!
  !real(c_double) :: cptr
  integer(C_INTPTR_T) :: adptr
  real(8), pointer :: array_data(:)
  real(8) dx
  integer(8) i8adptr
  integer(8) i8cptr
  !
   nbounds = SafeArrayGetDim (VBArray)
   allocate (bounds(nbounds), indexes(nbounds))
  
  do i=1,nbounds
    ires = SafeArrayGetLbound (VBArray, i, bounds(i)%lb)
    ires = SafeArrayGetUbound (VBArray, i, bounds(i)%ub)
  end do
  open (2, file="testout.txt", status="unknown")

  write (2, *) "Shape of the array passed by VB:"  
  write (2,'("  (")',advance='no')
  do i=1,nbounds
    write (2,'(I0,":",I0)',advance='no') bounds(i)
    if (i < nbounds) write(2,'(",")',advance='no')
    end do
  write (2,'(")")')
  !
  indexes = bounds%lb  ! Initialize to all lower bounds
  
  close (2) ! We're done with the file


  iRes=SafeArrayAccessData(VBArray,adptr)
  cptr=transfer(adptr,c_null_ptr)
  ! trouble
    call c_f_pointer(cptr,array_data,[4])
  !
  array_data(4)=PI*array_data(1)*array_data(1)*array_data(2)*array_data(3)/4.0
  deallocate (bounds)
  deallocate (indexes)
  return  
    end subroutine DF1
!    
!DEC$ ATTRIBUTES DLLEXPORT::df2
  !DEC$ ATTRIBUTES ALIAS:'DF2' :: DF2
SUBROUTINE DF2(D0,D1,D2,D3,LLEN)
IMPLICIT NONE
  ! Variables
REAL(8), INTENT(IN) :: D0
REAL(8), INTENT(IN) :: D1
REAL(8), INTENT(IN) :: D2
REAL(8), INTENT(OUT) :: D3
INTEGER(4), INTENT(IN) :: LLEN
REAL(8),PARAMETER :: PI  = 4 * atan (1.0_8)
  ! Body of df1
D3=PI*D0*D0*D1*D2/4.0
!
RETURN
end subroutine df2







