将.NET库与GO共享

huangapple go评论105阅读模式
英文:

Share .Net libraries with GO

问题

我正在寻找一种方法来编写一个使用.NET UI的GO应用程序,或者反过来,一个调用GO库的.NET应用程序。

有没有办法在GO中进行P'Invoke,或者从GO中进行".Net'Invoke"?

如果没有,最好的性能替代方案是什么?我目前想到的最好的主意是使用RPC。

英文:

I'm looking for a way to write a GO application that use a .NET UI. Or the other way around, a .Net application that calls into a GO library.

Is there anyway to P'Invoke GO, or ".Net'Invoke" from GO?

If not, what is the best performing alternative? The best idea I have right now is RPC.

答案1

得分: 2

可以在进程内托管.NET CLR。理论上,你可以编写一个可从C调用的DLL,该DLL可以托管CLR。

例如,这个示例项目演示了在C++应用程序内创建CLR。

如果将所需的状态(例如ICLRRuntimeInfo等)捆绑到一个结构体中,你应该能够从用C编写的DLL中调用相应的函数,并返回一个“句柄”或其他包装器给你的Go应用程序。

从文档中并不完全清楚的是:

  • 在另一个进程中加载的程序集是否可以执行这些调用(与进程本身相比)

  • 是否必须使用C++而不是C(似乎不是必须的,但我没有尝试过上述操作,并且在一些示例代码中有一些“可疑”的声明,涉及到纯C)

英文:

It is possible to host a .NET CLR in-process. You could in theory write a DLL callable from C, which could host such a CLR.

e.g. This example project demonstrates creating a CLR inside of a C++ application.

If you bundle together the required state (e.g. ICLRRuntimeInfo et al.) into a struct, you should be able to call the equivalents from a DLL written in C, and return a 'handle' or some such other wrapper to your Go application.

What is not entirely clear from the documentation is

  • Whether it's legal for an assembly loaded in another process to perform these calls (vs. the process itself)
  • Whether C++ is mandatory instead of C (doesn't seem to be the case, but I have not attempted the above and there are some 'suspicious' declarations in some of the example code w.r.t vanilla C)

huangapple
  • 本文由 发表于 2014年2月6日 05:48:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/21589245.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定