duandao8607 2017-06-09 00:01
浏览 838
已采纳

从Go语言调用的C#DLL(类库)函数

Hello Go Lang and C# gurus,

Good day. I would like to ask if anyone of you have tried calling a C# DLL functions (Class Library type) from a Go program?

I have made some initial research and saw these articles:

- https://github.com/golang/go/wiki/WindowsDLLs
- https://stackoverflow.com/questions/27849137/golang-call-windows-dll-functions

But these are DLLs created out from C Win32 implementations. I tried searching for C# DLL loaded into Go program all of them will tell you that you need to have a C++/C (Win32) wrapper before you can call it on a Go program.

Plus, the links above will tell you that Go is expecting a "C" declaration I think (which is of type __declspec) or the likes (e.g. WINAPI).

Is there a way in this case where we can completely skip the C/C++ wrapper and directly call the C# DLL functions in Go?

Your enlightening ideas and inputs will be greatly appreciated =)!

Thanks

  • 写回答

1条回答 默认 最新

  • duanjianao0592 2017-06-09 02:52
    关注

    Option 1 Turn your .NET DLL into a COM component like this, then you can invoke it from golang following the steps in your first link. Remember this option is for windows only.

    Option 2 Wrap the DLL within a simple C# console application, and invoke the application in golang using os/exec. Your final program is still cross-platform if your C# DLL is cross-platform.

    Both options need a basic knowledge of C#, either creating COM components, or writing a console application to invoke the DLL. IMO the latter is easier.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档