Z
zzb1984
Unregistered / Unconfirmed
GUEST, unregistred user!
在dll我设了个全局变量path<br>我在dll的函数a中改变了path的值<br> path := GetCurrentDir;<br>但当我在函数b中的<br>if length(path) <= 0 then<br> path := 'null';<br>path居然为'null'<br><br>难道在dll中无法在不同函数中共享全局变量吗<br>全部代码如下<br>unit HKProc;<br><br>interface<br><br>uses<br> Windows, Messages, Dialogs, SysUtils, TLHelp32;<br><br>var<br> hNextHookProc: HHook;<br> procSaveExit: Pointer;<br> userName, path : string;<br> lpBuffer :array[1..64] of Char;<br> nSize :Cardinal;<br> myfile : textfile;<br><br>function shellproc(iCode: Integer;<br> wParam: WPARAM;<br> lParam: LPARAM): LRESULT; stdcall; export;<br>function EnableHotKeyHook: BOOL; export;<br>function DisableHotKeyHook: BOOL; export;<br>procedure HotKeyHookExit; far;<br><br><br>implementation<br><br>function shellproc(iCode: Integer;<br> wParam: WPARAM;<br> lParam: LPARAM): LRESULT; stdcall; export;<br>var<br> szTitle:string; //当前窗口名称<br> temp : TDateTime;<br> processPath:string;<br> Handler : THandle;<br>begin<br> Result := 0;<br> If iCode < 0 Then<br> begin<br> Result := CallNextHookEx(hNextHookProc, iCode, wParam, lParam);<br> Exit;<br> end<br> else if iCode=HSHELL_WINDOWCREATED then<br> begin<br> SetLength(szTitle, 255);<br> SetLength(szTitle, GetWindowText(wParam,pchar(szTitle),254));<br><br>{ nSize := 255;<br> GetUserName(@lpBuffer, nSize);<br> userName := Copy(lpBuffer, 1, nSize-1);<br> path := GetCurrentDir;<br> path:=path + '/' + userName + DateToStr(now()) +'.txt';<br> AssignFile(myfile, 'E:/delphiProgram/managerComputer/windowtext.txt');<br> append(myfile);<br> Writeln(myfile, Path );<br> CloseFile(myfile);<br>}<br><br> if length(path) <= 0 then<br> path := 'null';<br> AssignFile(myfile, 'E:/delphiProgram/managerComputer/windowtext.txt');<br> append(myfile);<br> Writeln(myfile, Path );<br> CloseFile(myfile);<br><br> end;<br>end;<br><br><br>function EnableHotKeyHook: BOOL; export;<br>begin<br> nSize := 255;<br> GetUserName(@lpBuffer, nSize);<br> userName := Copy(lpBuffer, 1, nSize-1);<br> path := GetCurrentDir;<br> path:=path + '/' + userName + DateToStr(now()) +'.txt';<br> AssignFile(myfile, 'E:/delphiProgram/managerComputer/windowtext.txt');<br> append(myfile);<br> Writeln(myfile, Path );<br> CloseFile(myfile);<br><br> Result := False;<br> if hNextHookProc <> 0 then Exit;<br> // 挂上 WH_KEYBOARD 这型的 HOOK, 同时, 传回值必须保留下<br> // 来, 免得 HOOK 呼叫链结断掉<br> hNextHookProc := SetWindowsHookEx(WH_SHELL,<br> shellproc,<br> HInstance,<br> 0);<br> Result := hNextHookProc <> 0;<br>end;<br><br><br>function DisableHotKeyHook: BOOL; export;<br>begin<br> if hNextHookProc <> 0 then<br> begin<br> UnhookWindowshookEx(hNextHookProc); // 解除 Keyboard Hook<br> hNextHookProc := 0;<br> MessageBeep(0);<br> MessageBeep(0);<br> end;<br> Result := hNextHookProc = 0;<br> end;<br><br>procedure HotKeyHookExit;<br>begin<br> // 如果忘了解除 HOOK, 自动代理解除的动作<br> if hNextHookProc <> 0 then DisableHotKeyHook;<br> ExitProc := procSaveExit;<br>end;<br><br>end.<br><br>