golang go-ole 'Bad variable type' when calling Delphi functions

212 views
Skip to first unread message

Paweł Borkowski

unread,
Jun 6, 2014, 7:04:31 AM6/6/14
to golan...@googlegroups.com
I have COM objected implemented by a Delphi library 'ServerRS.Transmission' that has e.g. 'SerVarGlTxt' method (takes 2 strings). Unfortunately, it's proprietary library and I don't have access to it's source code.
When running following code:

package main

import (

"log"
)

func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.Lshortfile)
err := ole.CoInitialize(0); if err != nil {
log.Fatal(err)
}
unknown, err := oleutil.CreateObject("ServerRS.Transmission"); if err != nil {
log.Fatal(err)
} else {
log.Printf("Unknown: %v", unknown)
}
rsTransmission, err := unknown.QueryInterface(ole.IID_IDispatch); if err != nil {
log.Fatal(err)
}
log.Printf("dispatch: %T %v", rsTransmission, rsTransmission)
result, err := oleutil.CallMethod(rsTransmission, "SetVarGlTxt", "foo", "bar"); if err != nil {
log.Fatal(err)
}
log.Printf("SetVarGlTxt: %v", result)
}

I got following error (logs from oleutil and idispatch come from my debugging)

>go install && comobj
2014/06/06 12:53:39.448703 comobj.go:18: Unknown: &{0x7fefdeb68f8}
2014/06/06 12:53:39.450656 comobj.go:23: dispatch: *ole.IDispatch &{0x7fefe144f5
0}
2014/06/06 12:53:39.451632 idispatch.go:78: getIDsOfName [SetVarGlTxt] => [11]
2014/06/06 12:53:39.453585 oleutil.go:50: dispid = [11]
2014/06/06 12:53:39.453585 idispatch.go:172: serializing value foo as VT_BSTR
2014/06/06 12:53:39.454562 idispatch.go:172: serializing value bar as VT_BSTR
2014/06/06 12:53:39.454562 idispatch.go:212: puArgErr = 0
2014/06/06 12:53:39.455539 idispatch.go:214: Invoke hr != 0 [80020008]
2014/06/06 12:53:39.455539 comobj.go:25: Bad variable type.

I managed to create C++ code that calls the function with success. The parameter setting part of the working C++ looks like:
DISPPARAMS setVarParams;
setVarParams.rgvarg = new VARIANTARG[2];
VariantInit(&setVarParams.rgvarg[0]);
VariantInit(&setVarParams.rgvarg[1]);
setVarParams.rgvarg[1].vt = VT_BSTR;
setVarParams.rgvarg[1].bstrVal = SysAllocString(name);
setVarParams.rgvarg[0].vt = VT_BSTR;
setVarParams.rgvarg[0].bstrVal = SysAllocString(value);
setVarParams.cArgs = 2;
setVarParams.cNamedArgs = 0; 

I browsed through the go-ole code, idispatch.go especially, and it looks like both the go and C++ code are doing the same job when building the parameters.
I am stuck. Any ideas how to proceed from here?


Lubos Pintes

unread,
Jun 6, 2014, 10:52:41 AM6/6/14
to golan...@googlegroups.com
Try your simple example with package
code.google.com/p/com-and-go
> 2014/06/06 12:53:39.455539 comobj.go:25: *Bad variable type.*
>
> I managed to create C++ code that calls the function with success. The
> parameter setting part of the working C++ looks like:
> DISPPARAMS setVarParams;
> setVarParams.rgvarg = new VARIANTARG[2];
> VariantInit(&setVarParams.rgvarg[0]);
> VariantInit(&setVarParams.rgvarg[1]);
> setVarParams.rgvarg[1].vt = VT_BSTR;
> setVarParams.rgvarg[1].bstrVal = SysAllocString(name);
> setVarParams.rgvarg[0].vt = VT_BSTR;
> setVarParams.rgvarg[0].bstrVal = SysAllocString(value);
> setVarParams.cArgs = 2;
> setVarParams.cNamedArgs = 0;
>
> I browsed through the go-ole code, idispatch.go especially, and it looks
> like both the go and C++ code are doing the same job when building the
> parameters.
> I am stuck. Any ideas how to proceed from here?
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to
> golang-nuts...@googlegroups.com
> <mailto:golang-nuts...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.


John Jeffery

unread,
Jun 6, 2014, 7:59:20 PM6/6/14
to golan...@googlegroups.com
Just a wild guess, but are you compiling with GOARCH=386? You have to be in 32 mode to interop with old COM components. You probably are, because I'd be suprised if your program got as far is it did if it was GOARCH=amd64


Reply all
Reply to author
Forward
0 new messages