如何从 Fortran dll 调用 C# 代码
目前我有 abc.dll,它是 fortran dll。 现在我想从 abc.dll 调用 C# 代码。 有没有办法从 fortran dll 调用 C# 代码?
谢谢 萨加尔
Currently I have abc.dll which is fortran dll. Now I want to call C# code from abc.dll. Is there any way to call the C# code from fortran dll ?
thanks
Sagar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,如果您的程序完全用本机代码编写(我相信 Fortran dll 就是这样),您将需要调用从另一个本机代码模块导出的方法 (
dllexport
)。 在这种情况下,您需要创建一个托管 C++ dll,它公开本机接口并在内部对 C# 代码进行调用。编辑:如果托管程序是托管代码,并且您需要执行 C#->Fortran(本机)->C# 调用序列,则可以将委托用作非托管函数指针,如上面注释中链接的那样。 但是,如果可执行文件不是托管代码,则您需要采用我提到的路线。
Typically, if your program is written entirely in native code (as I believe the Fortran dll would be), you'll need to call a method that's been exported (
dllexport
) from another native code module. In this case, you'll want to create a Managed C++ dll that exposes a native interface and internally makes the call into the C# code.Edit: If the hosting program is managed code, and you need to do a C#->Fortran (native)->C# calling sequence, then delegates as unmanaged function pointers can be used as linked in the comments above. However, if the executable is not managed code, you'll need to go the route I mentioned.
支持最新 Fortran 语言功能(2003 标准)的编译器将支持 C 互操作。 您可以使用
ISO_C_BINDING
模块和BIND
构造通过其 C 接口与其他代码进行交互。 大多数最新的编译器都有它,它是标准的,您可以找到很多文档(例如 这个)通过 Google 搜索关键字 ISO_C_BINDING。Compilers supporting recent Fortran language features (the 2003 standard) will support C-interoperation. You interface with other code through its C interface, using the
ISO_C_BINDING
module and theBIND
construct. Most recent compilers have it, it's standard and you can find a lot of documentation (like this one) by Google'ing the keyword ISO_C_BINDING.