So I want to use the redemption COM library in go.
I could already successfully use it by registering it first and then using Go-OLE to call functions.
But ideally I want to use it without having to register it first.
When I searched on linking a dll in go I have found many answers saying to use cgo, but I could not find a tutorial, describing on how to use cgo.
After reading the cgo documentation, and this answer about cross compiling (I am cross compiling from Ubuntu linux amd64 to windows amd64) I figured that I could probably use the dll by setting my environment variables to
GOOS=windows;GOARCH=amd64;CGO_ENABLED=1;CXX=x86_64-w64-mingw32-g++;CC=x86_64-w64-mingw32-gcc
And writing a go file like this
package main
//#cgo windows LDFLAGS: -L/go/src/tryingout/Redemption64.dll
import "C"
import "fmt"
func main() {
session := C.Redemption.RDOSession
fmt.Println(session)
}
Unfortunately this did not work, I received the could not determine kind of name for C.Redemption error at compilation. I have looked it up and it means that Redemption does not exist. But I do know that it should be called like this since 1)It should be according to the documentation of redemption and 2) It worked before with go-ole
There is also a loader class written in C#, C++ and other languages by the redemption developer but I could not use that either because it was somehow always interpreted as C instead of C++ and thus resulted in errors. I tried this solution and added -lstdc++ to my LDFLAGS, but it made no difference.
So my question is how do I load and use this COM library or where can I find a tutorial/example code that explains it?
cgoandgccit will call) the types and functions in the DLL. I mean, "old" DLLs (not those files produced by .NET compilers which bear almost no resemblance to those "old" libraries except the extension part of their filenames) do not contain any information in them directly digestible bycgo. The latter has no direct support for COM and won't extract TLB info from the DLL (even if present)..hfiles suitable for feeding to a C compiler? Also note that whilecgois able to build C++ sources, it's not able to parse C++ from header files—hence it only is able to compile C++ code, but if you want to use it viacgo, the library must export a set of symbols using the C++'sextern "C" { ... }declaration.cgoneeds a.hfile to digest a DLL library. To your question: As far as I know, the only.hfile that I can access is theRedemptionLoader.hfile which comes together with theRedemptionLoader.cppfile. And if I see this correctly theRedemptionLoader.hfile is written in C++.RedemptionLoader.cppdoes not export symbols, so I will look into if I can export the necessary symbols myself using the documentation that I have. Tank you again for your helpful comments.CoInitialize[Ex]in the thread in which you intend to instantiate and use any COM[+] objects.go-olehas it already available. Also note that since the Go runtime implements the so-called M×N scheduling, any goroutine is free to run on any OS thread available to the scheduler at any given time. IOW it may switch threads at any time, andCoInitialize[Ex]initializes a thread, not a goroutine.