W
wp231957
Unregistered / Unconfirmed
GUEST, unregistred user!
loadlibrary('hookapi.dll');<br> hMapObj := OpenFileMapping(FILE_MAP_WRITE,{获取完全访问映射文件}<br> False,{不可继承的}<br> LPCTSTR(MappingFileName));{映射文件名字}<br> if hMapObj = 0 then<br> begin<br> ShowMessage('不能定位内存映射文件块!');<br> Halt;<br> end;<br><br> pShMem := MapViewOfFile(hMapObj,FILE_MAP_WRITE,0,0,0);<br> if pShMem = nil then<br> begin<br> ShowMessage('映射文件错误'+ IntToStr(GetLastError));<br> CloseHandle(hMapObj);<br> Halt;<br> end;<br><br> FillChar(pShMem^, SizeOf(TShareMem), 0);<br> pShMem^.hProcWnd := Self.Handle;<br> fWndClosed:=false;<br>procedure TForm1.Button6Click(Sender: TObject);<br>begin<br> showmessage(inttostr(pshmem^.ftimerid )); //这里总是0 我已经在DLL中为其赋值为1<br><br>end;<br><br>//以下为DLL代码:<br>initialization<br> hMappingFile := OpenFileMapping(FILE_MAP_WRITE,False,MappingFileName);<br> if hMappingFile=0 then<br> begin<br> hMappingFile := CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShareMem),MappingFileName);<br> FirstProcess:=true; {这是第一个进程,即主程序}<br> end else FirstProcess:=false;<br> if hMappingFile=0 then Exception.Create('不能建立共享内存!');<br> pShMem := MapViewOfFile(hMappingFile,FILE_MAP_WRITE or FILE_MAP_READ,0,0,0);<br> if pShMem = nil then<br> begin<br> CloseHandle(hMappingFile);<br> Exception.Create('不能映射共享内存!');<br> end;<br> if FirstProcess then<br> begin<br> pShMem^.bCanSpyNow:=false;<br><br> end;<br> pshmem^.ftimerid:=1; //这里已经赋值了,为什么在主程序中始终为0呢<br>finalization<br> UnMapViewOfFile(pShMem); {取消映射视图}<br> CloseHandle(hMappingFile); {关闭映射文件句柄}