Quantcast
Channel: Intel® Software - Intel® Visual Fortran Compiler for Windows*
Viewing all articles
Browse latest Browse all 5691

Pass Allocatble Arrays to DLL Subroutine via Modules

$
0
0

Hi,

I am trying to use a derived type structure in a dll subroutine using modules. Here is my main program:

Program Main
   
!dec$ attributes dllimport::_DERIVEDTYPECONSTRCT
   
use PARAM

   real a,b
   integer c

    a=2.0
    b=3.0
    c=6

    allocate (MyArray(1))
    call DERIVEDTYPECONSTRCT (1,a,b,c)!
   
     deallocate (MyArray)
end

the module "Param" is defined as below:

    MODULE PARAM
   
    type Derived_type
    real length  
    real width 
    integer measurmentflag
 
    end type Derived_type
   
    type(Derived_type), allocatable :: MyArray(:)
         
    END MODULE

The derived type "MyArray" is declared in the modules and is allocated in the Main program. I want to use is it a subroutine which is defined in a dll project.The subroutine DERIVEDTYPECONSTRCT is built as a dll:

subroutine derivedtypeConstrct (i,x,y,z)!
   
   
!dec$ attributes dllexport::derivedtypeConstrct
!DEC$ ATTRIBUTES STDCALL,ALIAS:"derivedtypeConstrct" :: derivedtypeConstrct
!DEC$ ATTRIBUTES REFERENCE  :: i,x,y,z
     
use PARAM
    integer i
    real x
    real y
    integer z

    MyArray(i)%length=x
    MyArray(i)%width=y
    MyArray(i)%measurmentflag=z
 
end

The problem is that when the code enters subroutine derivedtypeConstrct, the array "MyArray" becomes undefined although I have "use PARAM". The code works fine if "MyArray" is not allocatable or if subroutine derivedtypeConstrct is not a dll. I am trying to use the dll later in visual basic where MyArray will be a structure (I am not if it will work though).

Thanks for your helps.

Arash

 


Viewing all articles
Browse latest Browse all 5691

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>