英文:
Can a dll made in c# be used in a golang application
问题
我已经创建了一个基本的类,在C#中将两个数字相加。我已经将其构建为一个dll文件,但是在尝试在Golang中调用时失败了。
目前在Golang中是否可能实现这个功能?如果可以,有人可以提供一个示例吗?
编辑:我已经包含了我最后一次尝试的代码。C#的dll文件只是一个将传入的两个数字相加的方法。
package main
import (
"fmt"
"syscall"
)
func main() {
var mod = syscall.NewLazyDLL("MathForGo.dll")
var proc = mod.NewProc("Add")
proc.Call(2, 3)
fmt.Printf("%v", proc)
}
英文:
I have created a basic class that adds two numbers in c#. I have built it into a dll but when attempting to call it in golang I am unsuccessful.
Is this possible currently in golang? If so can someone provide a example how to do this?
Edit: I have included the last attempt I made at doing this. The C# dll is simply a method that adds the two numbers that are passed in.
package main
import (
"fmt"
"syscall"
)
func main() {
var mod = syscall.NewLazyDLL("MathForGo.dll")
var proc = mod.NewProc("Add");
proc.Call(2,3);
fmt.Printf("%v",proc)
}
答案1
得分: 11
有一个在Github上的项目旨在实现这个功能。
https://github.com/matiasinsaurralde/go-dotnet
C#程序集与C或C++不同,不能像我们希望的那样使用syscall进行加载。
英文:
There is a project on Github that aims to do this.
https://github.com/matiasinsaurralde/go-dotnet
C# assemblies are not the same as C or C++ and will not load using syscall like we might want.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论