?
Solved

in dll module global variable

Posted on 2005-03-29
11
Medium Priority
?
417 Views
Last Modified: 2011-09-20
i have function in dll module   :

function SysMsgProc(code : integer; wParam : word; lParam : longint) : longint; stdcall;export;
var                                                                            
 windtext,windtext3, windir,windp: array [0..255] of char;
 str,stra,full_date,date_,time_,task,DBname:String;
 i:integer;
begin
  x:=x+1;
  log_dll('x - '+x);

  date_:=FormatDateTime('yyyy-mm-dd', Date+Time);
  time_:=FormatDateTime('hh:nn:ss', Date+Time);
  full_date:=FormatDateTime('dd/mm/yyyy hh:nn:ss', Date+Time);

 Result := CallNextHookEx(SysHook, Code, wParam, lParam);
 case code of
   HSHELL_WINDOWACTIVATED:
   begin
    Wnd := wParam;
    GetWindowText(Wnd, windtext, 255);
    GetWindowModuleFileName(Wnd, windp, 255);
    task:=ExtractFileName(windp);
     SaveData(buff_date,buff_start_time,time_,buff_task,buff_action,buff_windtext,buff_other);
     BufferData(date_,time_,task,'OPEN',windtext,IntToStr(Wnd));
   end;
  HSHELL_WINDOWCREATED:
...

see the part where :
  x:=x+1;
  log_dll('x - '+x);

thx x is  declared in var x:integer: at begining of script.

the log_dll functions  saves data to have some log data.
see the result log_dll

x - 1
x - 2
x - 3
x - 4
x - 5
x - 6
x - 7
x - 1
x - 2
x - 3
x - 1
x - 1
x - 1
x - 1
x - 2
x - 3
...

the  global variable suddenly have number 0 and starts from beginig  :/

why  in this function (function SysMsgProc(code : integer; wParam : word; lParam : longint) : longint; stdcall;export;)
the global variable suddenly changes. in main programm  and other dll file code there isnot used X variable.

how i can create global wariable  whitch will be usable in  this function  and other functions ?
0
Comment
Question by:andrezzz
[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
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 11

Expert Comment

by:pcsentinel
ID: 13653120
Are you sure that the dll is being loaded statically and not getting released and reloded by your calling program. This would have the effect you are witnessing

Regards
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13653129
What type is X declared as?
Are you sure no where else resets the value back to 0?
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13653176
Yup, if you are freeing the dll and recreating it then it will reset X
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 13

Expert Comment

by:BlackTigerX
ID: 13653551
keep the global variable in your program and pass it to the DLL
0
 
LVL 11

Accepted Solution

by:
robert_marquardt earned 750 total points
ID: 13653841
The problem is that such hook DLLs get loaded into all applications. Each DLL is a copy (at least for the data segment with the global variables).
So each DLL gets its own global variables and only the first one has initialized variables.
You need to create a shared segment to store the crucial variables (especially the hook handle).
Petr Vones has created a tool to patch the DLL. http://cc.borland.com/ccweb.exe/listing?id=15387
0
 

Author Comment

by:andrezzz
ID: 13653953
to mikelittlewood
i can define variable with other name  like 'blablabla'. the same effect.

how i can hold the x variable for recreating it ????

to robert_marquardt:
how i can create  shared segment to storre  this information  ???
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 13654042
Follow the link. It contains documentation.
0
 
LVL 2

Expert Comment

by:philipjc
ID: 13657967
Robert_marqurdt

Alas, your link has been taken over by the keyword advertizers.
0
 
LVL 2

Expert Comment

by:philipjc
ID: 13657979
Sorry wrong link, I only saw your last post
0
 
LVL 15

Expert Comment

by:mikelittlewood
ID: 13659675
I think a good option would be to keep the global variable in your program and pass it to the DLL from your other application like BalckTigerX suggested.
0
 
LVL 11

Expert Comment

by:robert_marquardt
ID: 13659822
That is not possible for a global hook. A global hook DLL is loaded into all applications.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month14 days, 3 hours left to enroll

801 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