Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Check if its been assigned activated

Posted on 2011-03-23
4
Medium Priority
?
346 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 1000 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 500 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 1000 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 500 total points
ID: 35361205
if Assigned(MainHook) then...

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

604 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