Subroutine Swap(A,B)
!DEC$ Attributes DllExport, StdCall,Reference, Alias:'Swap'::Swap
Implicit None
Double Precision A,B
Double Precision T
T=A
A=B
B=T
End Subroutine
包含不正确的外部函数声明的Sort函数如下:
Subroutine Sort(A,N)
!DEC$ Attributes DllExport,StdCall,Alias:'Sort'::Sort
Implicit None
Double Precision A(N)
Integer N
External Swap ! It doesn't work
Integer I,J,N1
N1=N-1
Do I=1,N1
Do J=I+1,N
If(A(I)>A(J)) Call Swap(A(I),A(J))
End Do
End Do
End Subroutine ! End of Sort
包含正确的外部函数接口声明的Sort函数如下:
Subroutine Sort(A,N)
!DEC$ Attributes DllExport,StdCall,Alias:'Sort'::Sort
Implicit None
Double Precision A(N)
Integer N
!External Swap ! It doesn't work
! The interface works
Interface
Subroutine Swap(A,B)
!DEC$ Attributes DllExport, StdCall,Reference, Alias:'Swap'::Swap
Double Precision A,B
End Subroutine
End Interface
Integer I,J,N1
N1=N-1
Do I=1,N1
Do J=I+1,N
If(A(I)>A(J)) Call Swap(A(I),A(J))
End Do
End Do
End Subroutine ! End of Sort
在C#中队导出函数的声明为:
[DllImport("FDLL.dll", CallingConvention = CallingConvention.StdCall)]
public static extern void Swap(ref double A, ref double B);
[DllImport("FDLL.dll", CallingConvention = CallingConvention.StdCall)]
public static extern void Sort(double[] A, int N);