| Fortran 这边用以下代码,这样,这个dll就和C语言完全一模一样了: 
 [Fortran] syntaxhighlighter_viewsource syntaxhighlighter_copycode Subroutine mainsolve(cprojectname) Bind(C,Name="mainsolve")
!DEC$ATTRIBUTES DLLEXPORT :: mainsolve
  use, intrinsic :: ISO_C_BINDING
  implicit none
  type(c_ptr) , value :: cprojectname
  character(len=16) , pointer :: projectname
  call c_f_pointer( cprojectname , projectname )
end subroutine mainsolve
 C#这边我不太懂。AI 给出的答案,不一定对:
 
 [C#] syntaxhighlighter_viewsource syntaxhighlighter_copycode using System;
using System.Runtime.InteropServices;
 
class Program {
    [DllImport("softplatdll.dll", CallingConvention = CallingConvention.Cdecl)]
    public static extern void mainsolve([MarshalAs(UnmanagedType.LPStr)] string str);
 
    static void Main() {
        // 调用DLL中的函数
        string a = "try";
        mainsolve(a);
    }
} |