可以贴出你的文件映射函数吗,我也遇到相同的问题<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=2492079<br>我是想把用钩子记录下的窗口标题栏名称保存到dll所在的文件夹<br>一开始,我在shellproc用path获得dll所在的文件夹的路径,path := GetCurrentDir;<br>结果当我打开一个网页时, <br>path:= H:/program files/internet explorer/IEXPLORE.EXE<br><br>为此我到EnableHotKeyHook:中,全局变量path := GetCurrentDir;<br>的确获得dll所在的文件夹的路径,但是通过全局变量path传不进shellproc<br>在shellproc中path 未改变,仍为空串<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><br><br>