CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Nov 2007
    Posts
    53

    Thread overrides?

    Is that possible? I imagine it is, just as overriding other functions is possible.

    Here's my situation:
    I have many functions that perform various tasks with varied types of loops all at different times.
    I want to be able to terminate a thread, properly, without having to custom write in a check in the varied loops of every single threaded function , just so that it terminates properly. (Since everyone warns to stay away from TerminateThread(HANDLE) ).

    Here's my idea:
    Have a function such as:
    Code:
    int myOverride(LPVOID) { return 0; }
    Simple as that, and use the address of this function to override the functions that are running.
    I have a mapping class/system that manages thread ID's, and thus, I can easily SuspendThread(HANDLE) at any time, and this works great, however, the thread is still existant in memory, and that's not good.
    so the next step is figure out how to override that suspended thread, with the one above.... and I was hoping someone could point me in the right direction for that.


    I have played with OpenGL hooking, and written very very basic FARPROC hooks that patch the address of a function to that of my own, which allows me to execute my own code within the address space of that function. So I suppose my problem with this, is I'm not sure how to do that for my OWN DLL, since the functions I've played with are always in an external DLL- of which I cannot see the code for. Not to mention, the functions I've overwritten before, are not threaded, which makes this situation all the more... interesting. Since I can have multiple dynamically allocated references to a single function - thus I can't simply override just the original function, is that not correct? I would imagine I need to override the specific thread that's running based on it's address in memory.... And that lead's to a further question.... If a thread is suspended, and then overriden, will resuming it actually execute, or just crash?

    I saw this: http://www.codeguru.com/cpp/misc/mis...cle.php/c3793/
    and it appears to do what I'm thinking of(Notably the Attach and Detach functions), but I haven't tried it yet because I'm thinking you guys would have better insight into this than myself in conjunction with an untested web link.... And I'd rather not waste time needlessly. Not to mention, I'd like to venture this path with my own code, not someone elses.

    Any help is greatly appreciated....
    Last edited by dcyuri7; November 26th, 2008 at 05:19 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured