Hello,
I'm new with ComfyJ. I'm just trying to integrate a very simple ActiveX I have done just to learn how to use it before doing the real work, but I'm having problems or doubts with events.
I'm trying to follow the ComfyJ programers guide the chapter 4.7 Registering Callbacks for Generated COM Components (COM Events Handling). So, this is teh way I'm trying to integrate my OCX:
private void createOleObject()
{
container.createObject(CLASSID);
manoloActiveForm = new IManoloActiveFormImpl(_container.getOleObject());
IConnectionPointContainer connectionPointContainer = new IConnectionPointContainerImpl(_container.getOleObject());
IID iid = new IID(IManoloActiveForm.INTERFACE_IDENTIFIER);
IConnectionPoint connectionPoint = connectionPointContainer.findConnectionPoint(iid);
ManoloActiveFormEventsHandler handler = new ManoloActiveFormEventsHandler();
connectionPoint.advise(handler);
}
But I get this error:
com.jniwrapper.win32.com.ComException: COM object method returns error code: 0x80040200; PERPROP_E_NOPAGEAVAILABLE
at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:681)
at com.jniwrapper.win32.ole.impl.IConnectionPointContainerImpl.findConnectionPoint(SourceFile:78)
at pruebamanolo.mainproject.Frame3.createOleObject(Frame3.java:93)
Line 93 is IConnectionPoint connectionPoint = connectionPointContainer.findConnectionPoint(iid);
What am I doing wrong?. Is there any other example that shows how integrate events?.
Thanks
Manuel Crespo
Hi Manuel,
Such COM exception (PERPROP_E_NOPAGEAVAILABLE) indicates that a COM object does not have an appropriate connection point for the IID that you have specified for findConnectionPoint() method. Please make sure that that IID is correct and/or COM object itself provides the ability to add the event subscribers.
-Serge
Thanks for the answer.
I'm still quite lost with events. I have been looking the post of Lars Hennig, Problems connecting to COM events on Aug 23, 2007 to try to see how to do it. I have change the object creation but now I have other problems. This is the method:
private void createOleObject()
{
container.createObject(CLASSID);
manoloActiveForm = new IManoloActiveFormImpl(_container.getOleObject());
IClassFactoryServer server = new IClassFactoryServer(IManoloActiveFormEventsServer.class);
server.registerInterface(IDispatch.class, new IDispatchVTBL(server));
server.registerInterface(IManoloActiveFormEventsServer.class, new IManoloActiveFormVTBL(server));
IClassFactory factory = server.createIClassFactory();
IDispatchImpl handler = new IDispatchImpl();
factory.createInstance(null, handler.getIID(), handler);
ManoloActiveFormEventsHandler manoloHandler = (ManoloActiveFormEventsHandler)server.getInstances().pop();
}
And now I get:
com.jniwrapper.JNIWrapperException: java.lang.NoSuchMethodException: pruebamanolo.manoloactiveformproj1.server.IManoloActiveFormEventsServer.getVisible()
at com.jniwrapper.JNIWrapperException.createException(SourceFile:60)
at com.jniwrapper.win32.com.server.CoInterfaceVTBL.a(SourceFile:282)
at com.jniwrapper.win32.com.server.CoInterfaceVTBL.b(SourceFile:22)
at com.jniwrapper.win32.com.server.CoInterfaceVTBL$VirtualMethodCallback.<init>(SourceFile:83)
at pruebamanolo.manoloactiveformproj1.server.IManoloActiveFormVTBL.<init>(IManoloActiveFormVTBL.java:27)
at pruebamanolo.mainproject.Frame3.createOleObject(Frame3.java:99)
createOleObject(Frame3.java:99) is this line:
server.registerInterface(IManoloActiveFormEventsServer.class, new IManoloActiveFormVTBL(server));
But in the IManoloActiveFormVTBL this exists:
public IManoloActiveFormVTBL(CoClassMetaInfo classMetaInfo)
{
super(classMetaInfo);
addMembers(
new VirtualMethodCallback[] {
new VirtualMethodCallback(
"getVisible",
new HResult(),
new Parameter[] {
new Pointer(new VariantBool())
},
0
),
I thought it were going to be easier to integrate events, for the moment I haven't understood it. I would thank any help, I even cannot reproduce the example that comes in the programers guide.
Thanks
Manuel Crespo
Hi Manuel,
It looks like the the created VTBL is incorrect. Can you please send us an example so we can reproduce and fix the issue?
-Serge
Hello Serge,
I have just sent by mail to comfyj-support@teamdev.com.
I hope you can help. I'm almost sure that is something I'm not doing right.
Many thanks
Manuel
Hi Manuel,
Unfortunately I was not able to send this message on your email address somehow (probably due to some email issues), so I am posting the replay on the forum.
Thanks for the sample application. I have investigated it and found the cause of the problem. It was in the following code:
IClassFactoryServer server = new IClassFactoryServer(IManoloActiveFormEventsServer.class);
//server.registerInterface(IManoloActiveFormEventsServer.class, new IManoloActiveFormVTBL(server)); <- this is incorrect
server.registerInterface(IManoloActiveFormEvents.class, new IDispatchVTBL(server)); // register the required COM interface
server.setDefaultInterface(IDispatch.class);
Actually the problem was in using incorrect interface and incorrect VTBL class in the registerInterface() method. In fact IManoloActiveFormEventsServer class implements IManoloActiveFormEvents COM interface and this interface should be registered. Also, itÂs incorrect to use the VTBL of another COM class (IManoloActiveFormVTBL) for it.
In case you register a COM interface which does not have an appropriate VTBL (if itÂs an dispinterface), then IDispatchVBTL class should be used by default.
I have fixed this issue, modified the code a little bit in several places and it started working correctly. The modified sources are attached.
Also, supposing that you are already using ComfyJ 2.4 build #902, please use the attached comfyj-generator-2.4.902.jar file instead of previous one. This updated JAR produces more correct Java wrappers.
Please try the updated application and let me know the results.
-Serge
Hello Serge,
Yes, now it works. I'm happy again. Thanks for your support and your patience for the beginners, as me.
Regards
Manuel