Link to home
Start Free TrialLog in
Avatar of andrezzz
andrezzz

asked on

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 ?
Avatar of pcsentinel
pcsentinel

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
What type is X declared as?
Are you sure no where else resets the value back to 0?
Yup, if you are freeing the dll and recreating it then it will reset X
keep the global variable in your program and pass it to the DLL
ASKER CERTIFIED SOLUTION
Avatar of robert_marquardt
robert_marquardt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andrezzz

ASKER

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  ???
Follow the link. It contains documentation.
Robert_marqurdt

Alas, your link has been taken over by the keyword advertizers.
Sorry wrong link, I only saw your last post
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.
That is not possible for a global hook. A global hook DLL is loaded into all applications.