Hey,
Am Montag, den 17.04.2017, 01:15 -0700 schrieb zhu kane:
> I managed to generated the Java interface and typeinfo for my custom COM library via using TlbCodeGenerator.
>
> The interface looks like below,
>
> [IFACE Description]
>
> I'm trying to consume the COM library via JNA platform like below(I'm copying the code from Word example of JNA),
>
> public static void main(String[] args){
> Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_APARTMENTTHREADED);
> Factory factory = new Factory();
> DataProvider ocrlibrary = factory.createObject(DataProvider.class);
> System.out.println(
> ocrlibrary.ProcessImg("
https://myserver.com/7d0aa90d-03ef-4c4f-84fe-ab8b02f1c302.jpg"));
>
> }
>
> But I always got below timeout exception when consuming my COM library,
>
> Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.TimeoutException
> at com.sun.jna.platform.win32.COM.util.Factory.runInComThread(Factory.java:172)
> at com.sun.jna.platform.win32.COM.util.Factory.createObject(Factory.java:151)
> at JNATest.main(JNATest.java:27)
> Caused by: java.util.concurrent.TimeoutException
> at java.util.concurrent.FutureTask.get(FutureTask.java:205)
> at com.sun.jna.platform.win32.COM.util.ComThread.execute(ComThread.java:157)
> at com.sun.jna.platform.win32.COM.util.Factory.runInComThread(Factory.java:170)
> ... 2 more
>
how long does processing take normally? The
com.sun.jna.platform.win32.COM.util.Factory uses a separate thread to
run the calls and that thread also imposes an upper limit of execution
time. By default the timeout is 5000ms. You can adjust that by
instanciating your Factory with your own ComThread like so (here 30s,
30000 ms):
Factory factory = new Factory(new ComThread("COM Thread", 30000, new
Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread t, Throwable e) {
// do something intelligent
}
}));
This will still run the code as Multithreaded.
In your sample the CoInitializeEx is unnessary, as the ComThread exists
to make exaktly unnessary. You can try this:
public static void main(String[] args){
Ole32.INSTANCE.CoInitializeEx(Pointer.NULL, Ole32.COINIT_MULTITHREADED);
ObjectFactory factory = new ObjectFactory();
DataProvider ocrlibrary = factory.createObject(DataProvider.class);
System.out.println(ocrlibrary.ProcessImg("
https://myserver.com/7d0aa90d-03ef-4c4f-84fe-ab8b02f1c302.jpg"));
}
Can you offer access to the library you are using?
Greetings
Matthias