go - 在 Golang 中通过 COM 与 Lotus Notes 交互

标签 go com lotus-notes

我正在尝试访问 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/

相关文章:

java - 我在哪里可以设置 notes.ini 位置?

unit-testing - 如何在 Go 中将测试标记为不确定?

c# - 无法将 COM 对象转换为类类型

c# - 在 office 2010 中将受密码保护的 OpenXml Word 文档重新保存为受密码保护的二进制 Word 时显示错误

lotus-notes - 在嵌入 View 中显示对当前表单的响应

lotus-notes - 如何选择过去 7 天内的所有文档?

database - boltdb 是否支持并发查询来读取和更新数据库?

http - HTTP服务器HandleFunc循环超时?

mongodb - 如何通过golang中的mgo在mongo中插入math/big.Int

c# - 没有第二种形式的多线程消息泵