Solved

How to Check if its been assigned activated

Posted on 2011-03-23
4
338 Views
Last Modified: 2012-05-11
Hi, I'm having a problem, I'd like to be able to know if the hook is active and filled or empty.
var
MainHook : HHOOK;


//this creates
MainHook := SetWindowsHookEx(WH_JOURNALRECORD, KeyboardHook, hInstance, 0);

//this unhooks
UnhookWindowsHookEx(MainHook);
0
Comment
Question by:eNarc
  • 2
4 Comments
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 250 total points
ID: 35201336
Check if it returns zero

MainHook := SetWindowsHookEx(WH_JOURNALRECORD, KeyboardHook, hInstance, 0);
if MainHook > 0 then  //this was successful
  ........
0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 125 total points
ID: 35201520
HHook is of LongWord data type so to know if it is assigned a value you have to reset its default value first then you can match it to what you have set it to otherwise it will be holding a random default value.

You can test the default value this way:
var
  MainHook : HHOOK;
begin
  Showmessage(IntToStr(MainHook));

Open in new window


As you can see it will not be easy to distinguish if it's assigned that value or it's the default.
The best thing to do is, assign your own default value, let's say ZERO, and at any point if it is holding zero then it has not not assigned a value.
var
  MainHook : HHOOK;
begin
  MainHook := 0;
  //...
  // to check if it's assigned then
  If MainHook = 0 then
    // it is not assigned

Open in new window

0
 
LVL 32

Assisted Solution

by:ewangoya
ewangoya earned 250 total points
ID: 35238022

<so to know if it is assigned a value you have to reset its default value first >

No, you don't have to do that

var
   MainHook : HHOOK;
begin
   //the very first statement already assigns a value to it, you don't need to assign a default value
  MainHook := SetWindowsHookEx(WH_JOURNALRECORD, KeyboardHook, hInstance, 0);
0
 
LVL 2

Accepted Solution

by:
LelikInside earned 125 total points
ID: 35361205
if Assigned(MainHook) then...

Open in new window

0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question