我和周围同事都是写linux的,这次有用com组件写Windows程序的需求,c++、c#之类的不会只能用go,我研究了半天,找到了go-ole这个库,但是没找到合适的例子,如下表格是com接口方给的文档,下面的代码是我写的,但是最后结果感觉不太对,跪求大神解答问题出在哪里?
| 属性 | 值 |
| -------- | -------- |
| App ID | {0DCBF512-BB4D-48D0-932A-076456E6981D} |
| Type Library ID | {232E9616-F847-49F7-9AC3-095831429411} |
| Program ID | MedicareCom.Outpatient |
| COM ClassName | Outpatient Class |
| COM ClassID | {6ED3D8A4-FD47-4ED8-A93F-96EB87B5D830} |
| Interface Type | Dual Interface |
| Interface Name | IOutpatient 接口 |
| Interface ID | {D1ED1DEE-8994-431C-B048-C0586E4A4C31} |
```go
package main
import (
ole "github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
"fmt"
)
func main() {
ole.CoInitialize(0)
unknown, _ := oleutil.CreateObject("MedicareCom.Outpatient")
iid, _ := ole.IIDFromString("{D1ED1DEE-8994-431C-B048-C0586E4A4C31}")
q, _ := unknown.QueryInterface(iid)
r := oleutil.MustCallMethod(q, "Open", "") // 调用Open函数,没有参数
fmt.Println(r)
fmt.Printf("%+v\n", r)
}
```
执行后,最后结果如下,感觉不太对,预期应该返回结果的字符串,但返回个VT_EMPTY实在不懂,求哪位大神能解答一下,这个go调用com组件到底怎么写。
```shell
&{VT_EMPTY 0 0 0 0}
&{VT:VT_EMPTY wReserved1:0 wReserved2:0 wReserved3:0 Val:0}
```
<a href="/user/jjmgx" title="@jjmgx">@jjmgx</a> https://stackoverflow.com/questions/65818658/problem-passing-hex-long-parameter-to-com-method-using-go-ole
我碰到的问题和里面的小哥一样的,但是评论里的解决方法,我没用😂
#4
更多评论
我改成
```go
r, _ := oleutil.CallMethod(q, "Open")
```
r的值还是 &{VT:VT_EMPTY wReserved1:0 wReserved2:0 wReserved3:0 Val:0}
#2