Golang能封装成dll吗


当前第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

1

csc importgo.cs

将 exe 和 dll 放在同一目录下,运行。

1

2

3

4

>importgo.exe

Hello World!

From DLL: Bye!

55

更多golang知识请关注PHP中文网golang教程栏目。

以上就是Golang能封装成dll吗的详细内容,更多文章请关注木庄网络博客!!

返回前面的内容

相关阅读 >>

golang的内存管理(中篇)

go 字符串常用的系统函数

golang 如何处理死锁

go-carbon 1.3.3 版本发布,新增获取星座方法和判断是否是某个星座方法

golang】make和new区别,append

go - go build 各种系统下的可执行文件

golang在各平台下交叉编译

聊聊dubbo-go-proxy的jtypes

go - 实现项目内链路追踪(二)

golang mutex 源码解析

更多相关阅读请进入《golang》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...