Hello,
I have generated Code from an ocx file using CodegenForComfyJ.bat.
When I run the following code...
public class DirectSkinTest {
public static void main(String[] args) {
DefaultLibraryLoader.getInstance().addPath(".");
ComFunctions.coInitialize();
final _DWbocx lib = Wbocx.create(ClsCtx.INPROC_SERVER);
lib.setRootPath(new Int16(1));
}
}
...I get this exception:
Exception in thread "main" com.jniwrapper.win32.com.ComException: COM object method returns error code: 0x8000FFFF; E_UNEXPECTED (Schwerwiegender Fehler)
at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:744)
at com.jniwrapper.win32.com.impl.IUnknownImpl.invokeStandardVirtualMethod(SourceFile:723)
at com.jniwrapper.win32.automation.impl.IDispatchImpl.invoke(SourceFile:112)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.a(SourceFile:1121)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.a(SourceFile:1112)
at com.jniwrapper.win32.automation.Automation$InvocationHelper.invoke(SourceFile:1099)
at com.jniwrapper.win32.automation.Automation.a(SourceFile:914)
at com.jniwrapper.win32.automation.Automation.invoke(SourceFile:891)
at com.jniwrapper.win32.automation.Automation.invoke(SourceFile:964)
at com.jniwrapper.win32.automation.Automation.invokeDispatch(SourceFile:1221)
at directskin.wbocxlib.impl._DWbocxImpl.setRootPath(_DWbocxImpl.java:235)
at DirectSkinTest.main(DirectSkinTest.java:19)
What's wrong with my code and how can I fix it?
I have the following setup:
Windows XP
ComfyJ 2.7
comfyj.lic, jniwrap.lic, jniwrap.dll and the ocx file are contained in the directory where the application is executed (which I add in the above method).
The generated code and the ocx file from which it was generated are attached to this post.
Thanks in advance,
ASC
Hi,
Thanks for contacting our support and providing the complete example to reproduce the issue.
We will investigate it and let you know the solution soon.
-Serge
Hello,
for working with OCX component you should do initialization steps as it stated in our programmers guide section 4.5: http://www.teamdev.com/downloads/comfyj/docs/ComfyJ-PGuide.html#AEN418 .
Corrected sample code will look like this:
public class DirectSkinTest {
public static void main(String[] args) {
DefaultLibraryLoader.getInstance().addPath(".");
ComFunctions.coInitialize();
final _DWbocx lib = Wbocx.create(ClsCtx.INPROC_SERVER);
IUnknown ocxComponentWrapper = lib;
IOleObjectImpl oleObject = new IOleObjectImpl(ocxComponentWrapper);
// Initialize storage
ILockBytesImpl lockBytes = (ILockBytesImpl)
StorageFunctions.createILockBytesOnHGlobal(new GlobalMemoryBlock(), true);
IStorage storage = StorageFunctions.stgCreateDocfileOnILockBytes(lockBytes,
new StgMode(StgMode.STGM_READWRITE |
StgMode.STGM_SHARE_EXCLUSIVE | StgMode.STGM_CREATE),
new Int32());
// Initialize persist storage
IPersistStorageImpl persistStorage = new IPersistStorageImpl();
oleObject.queryInterface(persistStorage.getIID(), persistStorage);
persistStorage.initNew(storage);
lib.setRootPath(new Int16(1));
}
}
Regards,
Yuriy.
Hi Yuriy,
thank you. It seems that was exactly what was missing.
Somehow I thought the generated class would do this necessary steps for me.
Best regards,
ASC
Hello,
you really would not have to do these additional steps if you use that OCX control in GUI mode. Since OCX is a visual component you just need to embed it into OleContainer, which will do initialization steps for you.
Regards,
Yuriy.