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
Solved

How to Check if its been assigned activated

Posted on 2011-03-23
4
339 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 73
Working with hours 3 65
Delphi inherited method 6 76
File Downloader in Multi threading , Measure Download Speed and progress 9 11
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

828 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