Why does this work in Delphi5 but not Delphi6 ?

c++ / delphi package - dll injection and api hooking
Post Reply
cool_tester
Posts: 75
Joined: Sun Oct 31, 2004 5:45 am

Why does this work in Delphi5 but not Delphi6 ?

Post by cool_tester »

Hello all,
Could anyone tell me why the DLL_PROCESS_DETACH function below isn't fired by Delphi 6 where it gets fired properly by Delphi5? in fact no reason code is giving, when i unhook the dll, where the Attach gets fired upon loading.

Code: Select all

procedure DLLHandler( Reason : INTEGER );
begin
 case Reason of
  DLL_PROCESS_ATTACH:
   begin
   end;
  DLL_PROCESS_DETACH:
      begin
        // Your shutdown code goes here...
        MessageBox(0,'unloading','',0);
      end;
  DLL_THREAD_ATTACH:
      begin
      end;
  DLL_THREAD_DETACH:
      begin
      end;
  end;
end;

begin
 DLLProc := @DLLHandler;
 DLLHandler(DLL_PROCESS_ATTACH);
Basically if the dll is compiled with Delphi 5.0 when i unhook the injected dll i get the Unloading MessageBox, by if i compile in delphi6 i don't get the Unloading Message so in other words i don't think it gets fired at all, which causes my dll to crash because of not being able to cleanup. so if you could please help me fix this so it gets fired every time i unhook the dll.

Thanks,
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

I've tested it with D4, D5, D6 and D7 and it always works on my PC.
cool_tester
Posts: 75
Joined: Sun Oct 31, 2004 5:45 am

Post by cool_tester »

This is weired i'm using Win2k, and my dll has that exact code but the messageBox is never fired... what could it be?
I'm going nuts here...
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

Try using a lot file instead of a MessageBox. Maybe the DETACH event is fired, but the MessageBox is not shown (for whatever reason)?

How does the full dll code look like?
cool_tester
Posts: 75
Joined: Sun Oct 31, 2004 5:45 am

Post by cool_tester »

the dll has nothing but the above code, and still doesn't fire, just recompiled with Delphi 7 and it works.. so now it works on delphi 5 and 7, weired stuff. the only other thing i need to try is to update delphi 6.0, but i can't find the updates on Borlands Site... does anyone know where i can get these updates..

Oh yah i reinstalled delphi6 and no resolution yet, so now i'm installing it on a different machine just to see what happens.

Tried writing to a file and nothing so i know the event isn't fired... what could it be....? i don't rememeber changing anything on the ide setting and even if i did uninstaling and reinstalling delphi 6 should get the settings back to normal, and still no joy...

Thanks,
madshi
Site Admin
Posts: 10764
Joined: Sun Mar 21, 2004 5:25 pm

Post by madshi »

cool_tester
Posts: 75
Joined: Sun Oct 31, 2004 5:45 am

Post by cool_tester »

Thanks, for the link i swear i was at that link and the page kept taking me to Delphi 2005 downloads, anyway installing delphi 6 on another machine didn't fix the problem, let's see what happens after the updates, downloading them now.
cool_tester
Posts: 75
Joined: Sun Oct 31, 2004 5:45 am

Post by cool_tester »

Sure enough after the updates, the Unloading Box fires as it should, so in conclusion the Dlephi 6.0 original installation had a bug, there it goes days of testing...
and yes i learned my lesson, always install updates...

Thanks for your replies...
Post Reply