What do you mean? You're in process, and you're using CreateRemoteThread in EndScene? Don't. To remove the hooks after you're finished or whatever just simply DetourDetach( MS detours 2.1 ), DetourRemove( MS detours 1.5 ), or whatever you're using. Then destruct anything you have allocated using the new keyword with delete, would be a good idea to set any pointers that you're deleting to 0 after them.
Personally, I'm either way too tired and got up too early and don't really understand why you want to do this. You are probably having problems with removing hooks because you're using CreateRemoteThread. Why aren't you putting anything in DllMain? Just allocate a class, and do your stuff in the class constructor.
Something like this( i'm realllyyy tired, so don't take any notice if i'm completely wrong )
Code:
class CClass
{
public:
CClass(); // Constructor
~CClass(); // Destructor
};
CClass * gpClassWhatever = 0;
CClass::CClass()
{
// Attach your hooks here, whatever you want to do
}
CClass::~CClass()
{
// Detach your hooks here
}
BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReason, LPVOID )
{
switch( dwReason )
{
case DLL_PROCESS_ATTACH:
{
gpClassWhatever = new CClass();
break;
}
case DLL_PROCESS_DETACH:
{
delete gpClassWhatever;
gpClassWhatever = 0;
break;
}
}
return true;
}
I don't exactly understand what kind of answer you were expecting, so I hope this is somewhat helpful, because I saw that you were having problems how to start hooks too it seems in your injected DLL, CreateRemoteThread.. Don't get why you were doing that in-process. Also, if you're having problems on how to use hooks, google.