www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Object function cannot change member when called from callback?

So I have a window (Windows), and my wndProc is basically the 
same as the one on the windows guides. However, even though 
WM_CLOSE gets passed (and I can use if(msg == WM_CLOSE)), I can't 
seem to set my shouldClose flag. I've confirmed that I still get 
the event within my processMessage method. SO my question is 
this: what is going on, and how can I make it work?

extern (Windows) LRESULT wndProc(HWND hwnd, uint msg, WPARAM wp, 
LPARAM lp) nothrow {
     import std.stdio;
     import std.exception;

     Win32Window* window;

     if (msg == WM_NCCREATE)
         window = setWindowPtr(hwnd, lp);
     else
         window = getWindowPtr(hwnd);

     if (window !is null)
         return window.processMessage(msg, wp, lp);
     else
         return DefWindowProc(hwnd, msg, wp, lp);
}

Window {
     //--- other stuff ---//

     LRESULT processMessage(uint msg, WPARAM wp, LPARAM lp) 
nothrow {
         switch (msg) {
         case WM_CLOSE:
             _shouldClose = true; //tests as true here, but has no 
effect after method exits
             assumeWontThrow(writeln("close request received")); 
//this works
             return 0;
         default:
             return DefWindowProc(_hwnd, msg, wp, lp);
         }
     }
}

Sidenote, I can't build this with ldc2 for some reason: "cannot 
open input file 'kernel32.lib'". dmd seems to work just fine.
Jan 24 2017