yeah u must call EndDialog in side the window procedure. Or else you can post a message to window procedure to exit your dialog
Other wise you can use SendMessage to exit the window
public const int WM_COMMAND = 0x0112;
public const int WM_CLOSE = 0xF060;
SendMessage(pWnd, WM_COMMAND, WM_CLOSE, 0);