c# 调用
注意:如果调用失败,请尝试切换目标平台32或者64
//导入方法 [DllImport("main", EntryPoint = "PrintHello")] extern static void PrintHello(); [DllImport("main", EntryPoint = "Sum")] extern static int Sum(int a, int b); private void Form1_Load(object sender, EventArgs e) { MessageBox.Show(Sum(1, 2).ToString()); }
golang 编译类库
package main import "fmt" import "C" func main() { } func PrintHello() { fmt.Println("Hello From Golang") } func Sum(a, b int) int { return a + b }
编译执行: go build --buildmode=c-shared -o main.dll main.go