我正在尝试访问 Lotus Notes 客户端提供的 COM 类。在 Python 中,使用 win32com.client
库很容易做到这一点:
def initialize_notes(self):
"""
Initializes an object from the class.
:return: Lotus Notes database
"""
notes_session = win32com.client.Dispatch('Lotus.NotesSession')
notes_session.Initialize(self.notes_password)
notes_database = notes_session.GetDatabase(self.domino_server, self.domino_db)
return notes_database
现在在Go中,一直没有成功。下面是我的代码:
import (
"github.com/go-ole/go-ole"
"github.com/go-ole/go-ole/oleutil"
)
func Connect(dominoServer, database, notesPassword string) (*ole.IDispatch, error) {
ole.CoInitialize(0)
unknown, err := oleutil.CreateObject("Lotus.NotesSession")
if err != nil {
panic(err)
}
notes, err := unknown.QueryInterface(ole.IID_IDispatch)
if err != nil {
panic(err)
}
session := oleutil.MustCallMethod(notes, "Initialize", notesPassword).ToIDispatch()
db := oleutil.MustCallMethod(session, "GetDatabase", dominoServer, database).ToIDispatch()
return db, nil
}
出现以下错误 panic: Class not registered
。不过该类已注册,因为该函数的 Powershell 和 Python 版本都可以毫无问题地访问它。
我做错了什么?
最佳答案
如果 Go 在 64 位环境中执行,而 Powershell 和 Python 在 32 位环境中执行 - 反之亦然,那就是你的问题。请注意,Lotus COM 类是 unsupported in 64 bit environments .如果您正确注册它们,它们可以(大部分)工作,但一些调用确实会失败。如果我没记错的话,所有返回设计元素集合的方法都会失败,可能还有一些其他方法。
关于go - 在 Golang 中通过 COM 与 Lotus Notes 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46366215/