Solved

How to Check if its been assigned activated

Posted on 2011-03-23
4
334 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
Comment Utility
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
Comment Utility
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
Comment Utility

<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
Comment Utility
if Assigned(MainHook) then...

Open in new window

0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now