0
COM活動我試圖鉤住從Java的專有網絡協議棧。這個堆棧由一個COM對象提供,並且我設法使用com4j來掛鉤它。不幸的是,網絡堆棧是基於事件的,所以我需要我的代碼發出請求並訂閱提供響應的事件。訂閱與Com4j
每次我嘗試訂閱事件,我的代碼拋出一個包含堆棧跟蹤類似如下的com4j.ExecutionException:
Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040200 (Unknown error) : .\invoke.cpp:517
at com4j.ComThread.execute(ComThread.java:203)
at com4j.Task.execute(Task.java:25)
at com4j.Wrapper.advise(Wrapper.java:255)
at com4j.Wrapper.advise(Wrapper.java:18)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com4j.Wrapper.invoke(Wrapper.java:135)
at $Proxy5.advise(Unknown Source)
at main.Main.<init>(Main.java:14)
at main.Main.main(Main.java:131)
Caused by: com4j.ComException: 80040200 (Unknown error) : .\invoke.cpp:517
at com4j.Native.invoke(Native Method)
at com4j.StandardComMethod.invoke(StandardComMethod.java:42)
at com4j.Wrapper$InvocationThunk.call(Wrapper.java:335)
at com4j.Task.execute(Task.java:36)
at com4j.Wrapper$InvocationThunk.invoke(Wrapper.java:324)
at com4j.Wrapper.invoke(Wrapper.java:163)
at com4j.$Proxy9.FindConnectionPoint(Unknown Source)
at com4j.Wrapper$3.call(Wrapper.java:261)
at com4j.Wrapper$3.call(Wrapper.java:255)
at com4j.Task.invoke(Task.java:51)
at com4j.ComThread.run0(ComThread.java:153)
at com4j.ComThread.run(ComThread.java:134)
起初,我想的東西是錯我的代碼或與我的COM對象,所以我回到基礎知識,並試圖實現與com4j源碼一起提供的iTunes示例。他們的例子是這樣的:
public class Main {
public static void main(String[] args) throws Exception {
IiTunes iTunes = ClassFactory.createiTunesApp();
EventCookie cookie = iTunes.advise(_IiTunesEvents.class, new _IiTunesEvents() {
public void onDatabaseChangedEvent(Object deletedObjectIDs, Object changedObjectIDs) {
System.out.println("Database changed:" + deletedObjectIDs + "," + changedObjectIDs);
}
public void onPlayerPlayEvent(Object iTrack) {
System.out.println("Playing " + iTrack);
}
public void onPlayerStopEvent(Object iTrack) {
System.out.println("Stopped " + iTrack);
}
});
IITTrack track = iTunes.currentTrack();
if(track==null) {
System.out.println("Nothing is playing");
} else {
System.out.println("Now playing: "+ track.name());
}
System.out.println("Listening to events (will quit in 15 seconds)");
System.out.println("Play/stop songs in iTunes and see what happens");
Thread.sleep(15000);
cookie.close();
}
}
當我嘗試我的機器上運行這個例子,我得到就行了上面的異常
EventCookie cookie = iTunes.advise(_IiTunesEvents.class, new _IiTunesEvents() {...
沒有任何人有任何見解,爲什麼我可以」訂閱由COM對象拋出的事件?
我試着與我確實想換對象類似的代碼,並以同樣的方式,這使我相信,這個問題與我的開發環境做失敗。