Jump to content

Subclassing a window


Recommended Posts

So I tried to follow Valiks advice in this post and I nearly succeeded, at least I think so :o

I injected the code, so far so good.

I replaced the default WndProc with my own. Also without problems.

Filtering a message, now this is where the problems arise :P

My code for the injected dll look like this:

#include <windows.h>

WNDPROC original;

LRESULT CALLBACK SubWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{

    if (msg==WM_CLOSE)
        return 0;
    
    return DefWindowProc(hwnd,msg,wParam,lParam);
 //return CallWindowProcW(original,hwnd,msg,wParam,lParam);

}


BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
                     )
{
    HWND hwnd;
    hModule;
    lpReserved;
    

    switch (ul_reason_for_call)
    {
        case DLL_PROCESS_ATTACH:
            MessageBoxW(NULL,L"I am now injected, hehehe",L"Injected",NULL);
            hwnd=FindWindowW(NULL,L"Sample");
            original=(WNDPROC)SetWindowLongW(hwnd,GWL_WNDPROC,(long)SubWndProc);
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            break;
    }
    return TRUE;
}

If I inject it as it is now I totally screw up the window (duh), but if I call the original WndProc WM_CLOSE is still sent to it.

I guess I have got everything upside-down again...

Thanks in advance :P

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...