1

I'm trying to implement the Windows Restart Manager on my Java program and I got to the point where I'm receiving the messages from Windows and executing a callback that looks like this:

WindowProc proc = (hwnd, msg, wp, lp) -> {
    if (msg == WM_QUERYENDSESSION && lp.intValue() == ENDSESSION_CLOSEAPP) {
        // Here I need to return true to signify that the application is ready to quit.
     }
     // Pass the message to the default window procedure
     return user32.DefWindowProc(hwnd, msg, wp, lp);
};

where WindowProc looks like this:

private interface WindowProc extends StdCallLibrary.StdCallCallback {
    WinDef.LRESULT callback(WinDef.HWND hwnd, int msg, WinDef.WPARAM wp, WinDef.LPARAM lp);
}

According to the Restart Manager guidelines for Applications:

The Restart Manager queries GUI applications for shutdown by sending a WM_QUERYENDSESSION notification that has the lParam parameter set to ENDSESSION_CLOSEAPP (0x1). [...] GUI applications should listen for the WM_QUERYENDSESSION message and return a value of TRUE if the application is prepared to shut down and restart. [...]

How do I actually return true when the return value is a WinDef.LRESULT? I take it it's a pointer and somehow I need to construct a Win32 boolean and return a pointer to it?

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • no, try putting the value 1 in LRESULT. – Constantine Georgiou May 18 '18 at 11:09
  • @ConstantineGeorgiou: thank you. The problem with _trying_ is there's a lot to go wrong with using the Restart Manager from Java. I will try, and if it works, that'll be great, but if it doesn't, I won't really know whether it's this issue or a different one. – Pablo Fernandez May 18 '18 at 11:40
  • Sure, but my point is that you should return the value, not a a reference (pointer) to it. – Constantine Georgiou May 18 '18 at 13:52
  • `LRESULT` is pointer-**sized**. That doesn't mean, that it will always hold an actual pointer. In this case (as explained in comments above), you simply pass a boolean value, where 0 translates to `false` and any other value to `true`. 1 is a common value, which is what `TRUE` in the Windows API is defined as. – IInspectable May 18 '18 at 16:44
  • @ConstantineGeorgiou: Yes, that is correct, `1` represents `true` and I'm assuming `0` represents `false` although I didn't really test it. Do you want to put this as an answer so I can accept it? – Pablo Fernandez May 19 '18 at 11:43
  • You've got that backwards: `0` translates to `false`, while **all other values** translate to `true`. – IInspectable May 19 '18 at 11:56
  • Aside from non-0-non-1 numbers also representing true, that's what I said. – Pablo Fernandez May 19 '18 at 11:57

0 Answers0