module ftncode_mod use, intrinsic :: iso_c_binding implicit none type, public :: t_clb character(8) :: corf end type type, public :: t_bstuff type (t_clb) :: clb end type t_bstuff type, public :: t_stuff type (t_bstuff) :: substuff end type t_stuff contains subroutine c2fstr(cptr,fstr) type(c_ptr), value, intent(in ) :: cptr character(*), intent(out) :: fstr character(256), pointer :: lfstr integer :: id call c_f_pointer(cptr,lfstr) id = index(lfstr,char(0))-1 if(id.le.0) id=len(lfstr) fstr = lfstr(1:id) end subroutine function crfl() result(cp) bind(c) !DEC$ ATTRIBUTES DLLEXPORT :: crfl type(c_ptr ) :: cp type(t_bstuff), pointer :: fp allocate(fp) cp = c_loc(fp) end function function stfl(cstuff,cne) result(ierr) bind(c) !DEC$ Attributes dllexport :: stfl type(c_ptr), value, intent(in) :: cstuff type(c_ptr), value, intent(in) :: cne integer :: ierr type(t_bstuff) , pointer :: fstuff character(24) :: cwk ierr = 0 call c_f_pointer(cstuff,fstuff) call c2fstr(cne,cwk) fstuff%clb%corf = trim(cwk) end function subroutine test2(stuff) bind(c) !DEC$ATTRIBUTES DLLEXPORT :: test2 use iso_c_binding type(t_stuff), target, intent(in) :: stuff integer :: i i = 0 end subroutine test2 end module