Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

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 ?
0
andrezzz
Asked:
andrezzz
  • 3
  • 3
  • 2
  • +3
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now