我想访问Lotus Notes客户端提供的COM类。在Python这已经与win32com.client
LIB很简单:在Golang通过COM接口与Lotus Notes
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
现在走了,我都没有成功。下面是我的代码:
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版本都可以在没有问题的情况下访问它。
我在做什么错?
哪种操作导致恐慌? – captncraig
@captncraig好吧,我在第一个'恐慌(错误)'时引起恐慌,因为我无法加载类 – rhillhouse
CreateObject是一个通过特定注册表键查找ClassID的实用工具。请参阅[相关代码]中的评论(https://github.com/go-ole/go-ole/blob/8a4f5c214bfb4475619b8bb7ccbe6fa5c91745f4/com.go#L105)我猜它没有注册,并且python lib在做有些不同。 – captncraig