当前第2页 返回上一页
5、参考 exportgo.h 文件中的函数定义,撰写 C# 文件 importgo.cs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System;
using System.Runtime.InteropServices;
namespace HelloWorld
{
class Hello
{
[DllImport( "exportgo.dll" , EntryPoint= "PrintBye" )]
static extern void PrintBye();
[DllImport( "exportgo.dll" , EntryPoint= "Sum" )]
static extern int Sum(int a, int b);
static void Main()
{
Console.WriteLine( "Hello World!" );
PrintBye();
Console.WriteLine(Sum(33, 22));
}
|
编译 CS 文件得到 exe
将 exe 和 dll 放在同一目录下,运行。
1 2 3 4 | >importgo.exe
Hello World!
From DLL: Bye!
55
|
更多golang知识请关注PHP中文网golang教程栏目。
以上就是Golang能封装成dll吗的详细内容,更多文章请关注木庄网络博客!!
返回前面的内容
相关阅读 >>
聊聊gost的gosafely
详解 go 语言中的方法
一文搞懂如何实现 go 超时控制
golang之不可重入函数实现
mysql explain
golang 可以把包名去掉吗?
golang slice检查元素是否存在
基于go语言构建的万亿级流量大数据平台架构|文末彩蛋
golang如何实现收发邮件?
rabbitmq实现延迟队列
更多相关阅读请进入《golang》频道 >>
老貘
一个与时俱进的Go编程知识库。
转载请注明出处:木庄网络博客 » Golang能封装成dll吗