Print
View Comments
My very recent blog post "How to use EndTask" showed you how to use the windows api call "EndTask." This loaded the actual procedure from the user32.dll because the function wasn't declared in windows.h. Implementing an EndTask function is actually very simple and likely how Windows implements it internally. Here's the code:
1
2
3
4
5
6
7
8
9
10
11
BOOL WINAPI EndTask(_In_ HWND hWnd, _In_ BOOL fShutDown, _In_ BOOL fForce)
{
    SendMessageW(hWnd, WM_CLOSE, 0, 0);
 
    if(IsWindow(hWnd)) {
        if(fForce) return DestroyWindow(hWnd);
        else return FALSE;
    }
    
    return TRUE;
}

You're still going to need to include windows.h for obvious reasons. This implementation was found used in ReactOS.