in dll module global variable

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 ?
andrezzzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcsentinelCommented:
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
mikelittlewoodCommented:
What type is X declared as?
Are you sure no where else resets the value back to 0?
0
mikelittlewoodCommented:
Yup, if you are freeing the dll and recreating it then it will reset X
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

BlackTigerXCommented:
keep the global variable in your program and pass it to the DLL
0
robert_marquardtCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
andrezzzAuthor Commented:
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
robert_marquardtCommented:
Follow the link. It contains documentation.
0
philipjcCommented:
Robert_marqurdt

Alas, your link has been taken over by the keyword advertizers.
0
philipjcCommented:
Sorry wrong link, I only saw your last post
0
mikelittlewoodCommented:
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
robert_marquardtCommented:
That is not possible for a global hook. A global hook DLL is loaded into all applications.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.