简体   繁体   中英

C# DLL (Class Library) functions called from Go Language

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 (eg 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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM