I have a Windows DLL (XA_Session.dll) file but I don't know how to use it in golang.
This is a DLL Viewer picture
I want to use the ConnectServer
COM Method.
Here is my code
package main
import (
"syscall"
"fmt"
)
var (
mod = syscall.NewLazyDLL("XA_Session.dll")
proc = mod.NewProc("DllGetClassObject")
)
func main() {
var bConnect bool
bConnect = proc.ConnectServer("hts.ebestsec.co.kr", 20001)
if bConnect {
fmt.Println("Success")
} else {
fmt.Println("Fail")
}
}
compile error:
.\main.go:17: proc.ConnectServer undefined (type *syscall.LazyProc has no field or method ConnectServer)
I had a similar problem in my Direct3D9 Go wrapper, see this thread, where I was able to call DirectX COM functions from pure Go.
In your code you try to call
proc.ConnectServer(...)
but the way to call asyscall.LazyProc
is with itsCall
function. Looking at the documentation for DllGetClassObject, the signature isThis means you have to pass these three parameters to
proc.Call
asuintptr
s (Call
expects all arguments to beuintptr
s).Note that you need to set the parameter values correctly, the CLSID and IID may be contained in the accompanying C header file for the library, I don't know this XA_Session library.
The
ppv
will in this case be a pointer to the COM object that you created. To use COM methods from Go, you can create wrapper types, given you know all the COM methods defined by it and their correct order. All COM objects support theQueryInterface
,AddRef
andRelease
functions and then additional, type specific methods.Let's say your XA_Session object additionally supports these two functions (again, I don't know what it really supports, you have to look that up)
then what you can do to wrap that in Go is the following: