C#调用go语言生成的dll
Cgo
https://sourceforge.net/projects/mingw-w64/files/
离线安装
解压后,配置环境变量
gcc -v
go build --buildmode=c-shared -o Test.dll
package main
import "C"
import "fmt"
func main() {
fmt.Println(Test())
}
var _count = 99
// Test :
//
//export Test
func Test() int {
_count++
return _count
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp11
{
public partial class Form1 : Form
{
[DllImport("Test.dll", EntryPoint = "Test")]
extern static int Test();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
int r = Test();
MessageBox.Show(r.ToString());
}
}
}