gpt4 book ai didi

Java、Jacob 和 Microsoft Outlook 事件 : Receiving "Can' t find event iid"Error

转载 作者:行者123 更新时间:2023-12-04 06:51:31 25 4
gpt4 key购买 nike

我正在编写一个使用 Jacob library 与 Microsoft Outlook 交互的 Java 程序。 (桥接 COM 和 Java)。该程序创建了一个新的 MailItem , displaying它的 Inspector用户的窗口。我想订阅督察的Close event知道用户何时完成编辑他们的邮件项目。

要订阅该 Activity ,我按照 Jacob's documentation 中的说明进行操作。 (页面下方约 2⁄3):

The current [event] model is conceptually similar to the Visual Basic WithEvents construct. Basically, I provide a class called com.jacob.com.DispatchEvents which has a constructor that takes a source object (of type com.jacob.com.Dispatch) and a target object (of any type). The source object is queried for its IConnectionPointContainer interface and I attempt to obtain an IConnectionPoint for its default source interface (which I obtain from IProvideClassInfo). At the same time, I also create a mapping of DISPID's for the default source interface to the actual method names. I then use the method names to get jmethodID handles from the target Java object. All event methods currently must have the same signature: one argument which is a Java array of Variants, and a void return type.



这是我的 InspectorEventHandler类,符合雅各布的文档:
public class InspectorEventHandler {

public void Activate(Variant[] arguments) {

}

public void BeforeMaximize(Variant[] arguments) {

}

public void BeforeMinimize(Variant[] arguments) {

}

public void BeforeMove(Variant[] arguments) {

}

public void BeforeSize(Variant[] arguments) {

}

public void Close(Variant[] arguments) {
System.out.println("Closing");
}

public void Deactivate(Variant[] arguments) {

}

public void PageChange(Variant[] arguments) {

}

}

这是我如何使用此订阅事件 InspectorEventHandler类(class):
Object outlook = new ActiveXComponent("Outlook.Application");
Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();
Object inspector = Dispatch.get(mailItem, "GetInspector").getDispatch();

InspectorEventHandler eventHandler = new InspectorEventHandler();

// This supposedly registers eventHandler with the inspector
new DispatchEvents((Dispatch) inspector, eventHandler);

但是,最后一行失败并出现以下异常:
Exception in thread "main" com.jacob.com.ComFailException: Can't find event iid    at com.jacob.com.DispatchEvents.init(Native Method)    at com.jacob.com.DispatchEvents.(DispatchEvents.java)    at cake.CakeApplication.run(CakeApplication.java:30)    at cake.CakeApplication.main(CakeApplication.java:15)couldn't get IProvideClassInfo

According to Google, a few others have also received this error. Unfortunately, none of them have received an answer.

I am using version 1.7 of the Jacob library, which claims to prevent this problem:

Version 1.7 also includes code to read the type library directly from the progid. This makes it possible to work with all the Microsoft Office application events, as well as IE5 events. For an example see the samples/test/IETest.java example.

I noticed that the aforementioned IETest.java file subscribes to events like this:

new DispatchEvents((Dispatch) ieo, ieE,"InternetExplorer.Application.1");

因此,我尝试以类似的方式订阅我的事件:
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.1");
new DispatchEvents((Dispatch) inspector, eventHandler, "Outlook.Application.12");

所有这些尝试都失败了,并出现了相同的错误。

最佳答案

经过一些实验,我确定订阅 MailItem 's Close event 可以达到预期的效果。而不是 Inspector 's Close event .我现在有一个 MailItemEventHandler处理所有的类 MailItem events :

public class MailItemEventHandler {

public void AttachmentAdd(Variant[] arguments) {
System.out.println("AttachmentAdd");
}

public void AttachmentRead(Variant[] arguments) {
System.out.println("AttachmentRead");
}

public void AttachmentRemove(Variant[] arguments) {
System.out.println("AttachmentRemove");
}

public void BeforeAttachmentAdd(Variant[] arguments) {
System.out.println("BeforeAttachmentAdd");
}

public void BeforeAttachmentPreview(Variant[] arguments) {
System.out.println("BeforeAttachmentPreview");
}

public void BeforeAttachmentRead(Variant[] arguments) {
System.out.println("BeforeAttachmentRead");
}

public void BeforeAttachmentSave(Variant[] arguments) {
System.out.println("BeforeAttachmentSave");
}

public void BeforeAttachmentWriteToTempFile(Variant[] arguments) {
System.out.println("BeforeAttachmentWriteToTempFile");
}

public void BeforeAutoSave(Variant[] arguments) {
System.out.println("BeforeAutoSave");
}

public void BeforeCheckNames(Variant[] arguments) {
System.out.println("BeforeCheckNames");
}

public void BeforeDelete(Variant[] arguments) {
System.out.println("BeforeDelete");
}

public void Close(Variant[] arguments) {
System.out.println("Close");
}

public void CustomAction(Variant[] arguments) {
System.out.println("CustomAction");
}

public void CustomPropertyChange(Variant[] arguments) {
System.out.println("CustomPropertyChange");
}

public void Forward(Variant[] arguments) {
System.out.println("Forward");
}

public void Open(Variant[] arguments) {
System.out.println("Open");
}

public void PropertyChange(Variant[] arguments) {
System.out.println("PropertyChange");
}

public void Read(Variant[] arguments) {
System.out.println("Read");
}

public void Reply(Variant[] arguments) {
System.out.println("Reply");
}

public void ReplyAll(Variant[] arguments) {
System.out.println("ReplyAll");
}

public void Send(Variant[] arguments) {
System.out.println("Send");
}

public void Unload(Variant[] arguments) {
System.out.println("Unload");
}

public void Write(Variant[] arguments) {
System.out.println("Write");
}

}

我使用以下方法订阅事件:
Object outlook = new ActiveXComponent("Outlook.Application");
Object mailItem = Dispatch.call(outlook, "CreateItem", 0).getDispatch();

MailItemEventHandler eventHandler = new MailItemEventHandler();
new DispatchEvents((Dispatch) mailItem, eventHandler);

我对 COM 不太了解,但似乎 Inspector 有问题对象注册...

关于Java、Jacob 和 Microsoft Outlook 事件 : Receiving "Can' t find event iid"Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3052963/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com