I want to be able to call windows api shutdownBlockReasonCreate from my Java code. I know it's a complicated process involving JNI call to a custom c++ code that generates a dll. But I was able to get there eventually. However I have a problem with obtaining a HWND from my shell window (I use SWT) as it's one of the key parameters to shutdownBlockReasonCreate and shutdownBlockReasonDestroy functions. Without it I couldn't get these functions to work.
A particular implementation online https://github.com/seraphy/JavaGracefulShutdownForWin7 seems to provide the capabilities required and a demo in how this can be done. Unfortunately this was done with JFrame (using JAWT.lib) whereas my application window was written in Eclipse SWT / JFace. I'm not sure if Eclipse has anything equivalent.
I tried many different approaches such as using FindWindow function and ::FindWindowEx, as well as passing in Shell.handle
to the native methods. None of them worked for me as neither of them returns meaningful HWND value but '0'.
Since I'm not using JFrame, I cannot get HWND from JFrame like "seraphy" did. And certainly there's no way we can convert SWT Shell to a JFrame so I can reuse some of its code.
I also don't think JNA would help much in here either given my Google research over the last couple of days. I can see it was able to obtain a handle to a console window (How to return HWND in JAVA) but are we able to call shutdownBlockReasonCreate methods directly from JNA? Nothing online I found so far seemed to suggest that. In which case we still have to use JNI instead.
I'm very new to c++ so I'm a little bit struggled in getting this to work. Anyone who can shed some light or point me to the right direction would be very much appreciated!