Solved

How to Check if its been assigned activated

Posted on 2011-03-23
4
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 32

Assisted Solution

by:Ephraim Wangoya
Ephraim Wangoya 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:Ephraim Wangoya
Ephraim Wangoya 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

690 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