C#编写的DLL能在Golang应用程序中使用吗?

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

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.

huangapple
  • 本文由 发表于 2015年10月24日 13:48:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/33314958.html
匿名

发表评论

匿名网友

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

确定