0

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?

10
  • From a cursory look, my impression is what's missing is an inclusion of a header file actually defining (for cgo and gcc it 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 by cgo. The latter has no direct support for COM and won't extract TLB info from the DLL (even if present). Commented Dec 10, 2018 at 15:49
  • So the question is: does that "redemption" thing provide one or more "public" .h files suitable for feeding to a C compiler? Also note that while cgo is 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 via cgo, the library must export a set of symbols using the C++'s extern "C" { ... } declaration. Commented Dec 10, 2018 at 15:51
  • Thank you for this information, I did not know cgo needs a .h file to digest a DLL library. To your question: As far as I know, the only .h file that I can access is the RedemptionLoader.h file which comes together with the RedemptionLoader.cpp file. And if I see this correctly the RedemptionLoader.h file is written in C++. Commented Dec 10, 2018 at 22:15
  • The RedemptionLoader.cpp does 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. Commented Dec 10, 2018 at 22:28
  • 1
    Please note that should you succeed with either approach, do not forget that you have to call CoInitialize[Ex] in the thread in which you intend to instantiate and use any COM[+] objects. go-ole has 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, and CoInitialize[Ex] initializes a thread, not a goroutine. Commented Dec 11, 2018 at 10:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.