I am using JNA to access User32 features (I donโt think this is due to Java here, there is more of a problem with the concept). In my application, I have a Java process that interacts with the Canon SDK. To send any messages, I use the following function:
private void peekMessage(WinUser.MSG msg) throws InterruptedException { int hasMessage = lib.GetMessage(msg, null, 0, 0); if (hasMessage != 0) { lib.TranslateMessage(msg); lib.DispatchMessage(msg); } Thread.sleep(1); }
peekMessage is called in a loop and everything works well. Whenever the image is taken from the camera, I get an event and do the rest.
But I observed, say, after about 15 seconds (sometimes never, or sometimes just at startup) no activity with the camera, shooting does not give me any loading event. Later, the entire application becomes unusable because it does not receive any events from the camera.
What could be the reason for this? Please let me know about any other necessary information, I can insert the corresponding code.
Edit:
Initialization:
Map<String, Integer> options = new HashMap<String, Integer>(); lib = User32.INSTANCE; hMod = Kernel32.INSTANCE.GetModuleHandle(""); options.put(Library.OPTION_CALLING_CONVENTION, StdCallLibrary.STDCALL_CONVENTION); this.EDSDK = (EdSdkLibrary) Native.loadLibrary("EDSDK/dll/EDSDK.dll", EdSdkLibrary.class, options); private void runNow() throws InterruptedException { while (!Thread.currentThread().isInterrupted()) { Task task = queue.poll(); if (task != null) { int taskResult = task.call(); switch (taskResult) { case (Task.INITIALIZE_STATE): break; case (Task.PROCESS_STATE): break; case (Task.TERMINATE_STATE): {
Above, whenever I get an event of my camera, I add it to the queue , and in each loop I check the queue to handle any Task . Another important piece of information: this is a process running on cmd and not having a window. I just need events from my camera and nothing more.
Code in which I register callback functions:
/** * Adds handlers. */ private void addHandlers() { EdSdkLibrary.EdsVoid context = new EdSdkLibrary.EdsVoid(new Pointer(0)); int result = EDSDK.EdsSetObjectEventHandler(edsCamera, new NativeLong(EdSdkLibrary.kEdsObjectEvent_All), new ObjectEventHandler(), context).intValue(); //above ObjectEventHandler contains a function "apply" which is set as callback function context = new EdSdkLibrary.EdsVoid(new Pointer(0)); result = EDSDK.EdsSetCameraStateEventHandler(edsCamera, new NativeLong(EdSdkLibrary.kEdsStateEvent_All), new StateEventHandler(), context).intValue(); //above StateEventHandler contains a function "apply" which is set as callback function context = new EdSdkLibrary.EdsVoid(new Pointer(0)); result = EDSDK.EdsSetPropertyEventHandler(edsCamera, new NativeLong(EdSdkLibrary.kEdsStateEvent_All), new PropertyEventHandler(), context).intValue(); //above PropertyEventHandler contains a function "apply" which is set as callback function }