Jump to content
Tuts 4 You

Help me use SetWindowsHookEx.


Vic

Recommended Posts

Posted (edited)

Hi,
I need you help me. I want to use SetWindowsHookEx to hook a function exported from a dll to a run a process but it did not work. Detail: I'm have 3 files: Audition.exe, Hooker.exe & DllHook.dll, I'm using Hooker.exe to load that dll & execute function SetHook (exported in dll for Hooker.exe use it). SetHook function in dll will excute to use SetWindowsHookEx to hook a other function in dll into Audition.exe. If hook success it'll show a nag is the PID of Audition.exe process is running. But it's hook isn't success. I want to you help me.
This is code in DllHook:

library DllHook;uses
SysUtils,
Windows,
Classes;{$R *.res}Procedure Thread;
begin
MessageBox(0,PChar(IntToStr(GetCurrentProcessId)),PChar('PID '),MB_OK);
end;Procedure Main;
var
nul: Cardinal;
begin
CreateThread(nil,0,@Thread,nil,0,nul);
end;Procedure SetHook;
var
PID: Cardinal;
begin
GetWindowThreadProcessId(FindWindow(nil,'Audition'),@PID);
if SetWindowsHookEx(WH_CBT,@Main,0,PID) = 0 then
MessageBox(0,PChar('Hook is error...'),PChar('Error'),MB_OK);
end;exports
SetHook;begin
end.
Project:
This is project of it, i uploaded in attachment file. I hope yous hlp me right now. Tkz vzy much! Edited by vic4key
Posted

<irony>

1) Error handling is for sissies. Your code is so perfect that you will never need to know what went wrong. Oh, wait..

2) Who cares about calling conventions? Code compiles, so it should be fine..

3) ThreadId is the same as ProcessId. After all, it's just a number, right?..

4) nil, nul, NULL. Sounds the same, so they will work the same..

</irony>

Sorry, your code is broken in so many ways that nobody can help you. Go back to school, read a lot, learn a lot and start again from scratch.

Posted (edited)

Tkz kao, but i tried vzy much to find error into it but dont know where wrong. In my school after year learn Pascal. Not learn Delphi. Now we're learning Office. I'm vzy stupid. U can hlp me edit to hook successful? :) Tkz

Edited by vic4key

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
×
×
  • Create New...