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

从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 win11账户锁定时间设为0无法登录
  • ¥45 C#学生成绩管理系统
  • ¥15 VB.NET2022如何生成发布成exe文件
  • ¥30 matlab appdesigner私有函数嵌套整合
  • ¥15 vb6.0使用jmail接收smtp邮件并另存附件到D盘
  • ¥30 vb net 使用 sendMessage 如何输入鼠标坐标
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云