It's hard to tell what's going on when we can't see the code for CWindow. Otherwise your code seems to be the same as the template so that part should be fine.
Otherwise if you're using multithreading it might be a good idea to call ExitProcess(result) after PostQuitMessage(), as calling PostQuitMessage() alone will not terminate any background threads that you've spawned from D which are looping infinetly.
