Error when Passing matrices from MATLAB to FORTRAN dll
I have a simple intel fortran dll compiled from below:

    function  add1(A,n)
    !Expose  function  add1  to  users  of  this  DLL
    !DEC$ ATTRIBUTES  C,DLLEXPORT:: add1
    implicit none
    double  precision  A,add1
    integer n
    call add2(A,n)
    A=A+1.0
    add1=A
    end  function  add1
    
    subroutine add2(a,n)
    double precision a
    integer n
    a=a+1
    endsubroutine
I also have a header file for the dll:

    double* add1(double*,int);

I use MATLAB to load the dll:

    library='trydll.dll';
    header='add1.h';
    loadlibrary(library, header);
    n=3;
    haha=ones(n,n);
    A=calllib('trydll','add1',haha,n)
    unloadlibrary('trydll')

The sent matrix and the integer to the dll are severely wrong, and seem to be random numbers in the memory. Anyone has any idea where the mistake is?
Error when Passing matrices from MATLAB to FORTRAN dll
===

I have a simple intel fortran dll compiled from below:

    function  add1(A,n)
    !Expose  function  add1  to  users  of  this  DLL
    !DEC$ ATTRIBUTES  C,DLLEXPORT:: add1
    implicit none
    double  precision  A,add1
    integer n
    call add2(A,n)
    A=A+1.0
    add1=A
    end  function  add1
    
    subroutine add2(a,n)
    double precision a
    integer n
    a=a+1
    endsubroutine
I also have a header file for the dll:

    double* add1(double*,int);

I use MATLAB to load the dll:

    library='trydll.dll';
    header='add1.h';
    loadlibrary(library, header);
    n=3;
    haha=ones(n,n);
    A=calllib('trydll','add1',haha,n)
    unloadlibrary('trydll')

The sent matrix and the integer to the dll are severely wrong, and seem to be random numbers in the memory. Anyone has any idea where the mistake is?