I am getting following exception every time I try to post an asynchronous task by adding/posting a runnable task on the message loop using doInvokeLater method.
I am using ComfyJ 2.3 containing jniwrap-3.6 and winpack-3.6.
I was trying to upgrade existing code base to jniwrap 3.6 from jniwrap 2.9.5 which was working fine earlier.
com.jniwrapper.win32.com.ComException: COM object method returns error code: 0x80004005; E_FAIL (Unspecified error)
at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:658)
at com.tradingscreen.pisa.plugin.bloomberg.blp_data_ctrllib.impl.IBlpData4Impl.subscribe(IBlpData4Impl.java:59)
at com.tradingscreen.pisa.plugin.bloomberg.api.BBData$CmdSubscribe.run(BBData.java:291)
at com.jniwrapper.win32.MessageLoopThread$ThreadAction.run(MessageLoopThread.java:541)
at com.jniwrapper.win32.MessageLoopThread$LoopThread.run(MessageLoopThread.java:515)
Please advice.
Thanks a lot.
- Ani
Hi Ani,
There were many changes in both JNIWrapper 3.6 and ComfyJ 2.3 since version 2.9.5, so it is quite difficult to say exactly why such error happens.
Can you please send us the complete test case that demonstrates the problem? We will investigate it and give you the solution.
-Serge
Also, you probably need to generate the wrappers for your COM library anew, using the CodegenForComfyJ from ComfyJ 2.3.
Message was edited by: Serge Piletsky
Thanks a lot Serge !
Knowing that there were many changes in both JNIWrapper 3.6 and ComfyJ 2.3 since version 2.9.5, it is quite possible that I must take a closer look at at each method wrapper and also try to generate a new wrapper using CodegenForComfyJ from ComfyJ 2.3 as per your suggestion.
After doing this I will post my observations and questions if I come across any issues.
Thanks and regards,
Ani
Hi Serge,
I regenerated the wrappers using ComfyJ 2.3 but I am still getting the same error. What I see is that my first runnable (action) works fine but from the very next runnable which I add to OleMessageLoop immediately throws the reported exception.
Following is typical setup / test setup
The usage pattern is as follows:
class Test {
OleMessageLoop comMessagePump = new OleMessageLoop();
IComponent123 wrapped;
// Constructor
Test() { comMessagePump.doInvokeLater(new CmdCreate()); }
// Method
void doSomething() { comMessagePump.doInvokeLater(new CmdDoSomething("foo")); }
class CmdCreate implements Runnable {
CmdCreate() { comMessagePump.doStart(); }
void run() {
// Initializing COM on the dispatch thread and creating instance
ComFunctions.coInitializeEx(CoInit.APARTMENTTHREADED);
wrapped = Component.create(ClsCtx.INPROC_SERVER);
}
}
class CmdDoSomething implements Runnable {
String param;
CmdDoSomething (String param) { this.param= param; }
void run() { wrapped.doSomething(new BStr(param)); }
}
}
// in a routine far, far away...
String foo = {"asd", "qwe", "zxc"};
Test test = new Test();
for (int i=0; i<foo.length; i++) test.doSomething(foo+); >
Also following is the COM method which I am trying to invoke
Subscribe (BSTR Security, LONG Cookie, VARIANT Fields, VARIANT OverrideFields,
VARIANT Overrides, VARIANT Results, VARIANT Monitor);
My Java call looks like:
Variant requestedFields = fields==ALL_FIELDS ? ALL_FIELDS_CACHED
: new Variant(ComUtils.asSafeArray(fields));
Variant ovrFields = overrideFields==null ? UNSPECIFIED
: new Variant(ComUtils.asSafeArray(overrideFields));
Variant ovrValues = overrideValues==null ? UNSPECIFIED
: new Variant(ComUtils.asSafeVariantArray(overrideValues));
Variant resultBuffer = UNSPECIFIED; //Variant.createUnspecifiedParameter();
Variant monitor = TRUE; //new Variant(true);
comobj_.subscribe(
new Variant(security), new Int32(cookie),
requestedFields, ovrFields, ovrValues,
resultBuffer, monitor
);
ALL_FIELDS is safeArray
I am using jdk 1.5 update 09.
Do I need to change some data types after migrating from 2.8.5 version of jniwrapper to 3.6 ?
Do I need to set some other properties of OleMessageLoop ?
Please advise.
Thanks and regards,
Ani
Tried the first attempt solution but didn't work. Hence provided further information about test case and asked further advice.
The problem was fixed when I passed a parameter to com method created as local safe array of BStr objects with AutoDelete set to False instead of using a static final Variant wrapper over a safe array of BStr object with no autoDelete set on them.
Not sure what the default value for auto delete is on BStr.
Also not sure if static final variant could have caused this issue.
According to Mr. Serge, the first method call was nullifying BStr objects inside the safe array which was causing subsequent failures on this method invocations as the same static variant was being passed.
(I am still wondering how it was running with older version of jniwrapper)?
But thanks to Mr. Serge in helping me to sort out this issue.
I was finally able to upgrade to latest version of library.