首页
社区
课程
招聘
[求助]想给任务管理器的ListView增加一行,但出现内存错误
发表于: 2008-4-17 13:25 4817

[求助]想给任务管理器的ListView增加一行,但出现内存错误

2008-4-17 13:25
4817
写内存写错了

procedure TForm1.Button1Click(Sender: TObject);
var
pItem: TLVItem;
Buff: PChar;
PID,PRC: THandle;
R: Cardinal;
hwnd:tHandle;
begin
        hwnd:= FindWindow('#32770','Windows 任务管理器');
        hwnd:= FindWindowEx(hwnd,0,'#32770',0);
        hwnd:= FindWindowEx(hwnd,0,'SysListView32',0);

  GetWindowThreadProcessId(hwnd, @PID);
  PRC := OpenProcess(PROCESS_VM_OPERATION or PROCESS_VM_READ or
  PROCESS_VM_WRITE, False, PID);
  Buff := VirtualAllocEx(PRC, nil, 4096, MEM_RESERVE or MEM_COMMIT,
  PAGE_READWRITE);
  ZeroMemory(@pItem,SizeOf(pItem));
  with pItem do
  begin
    mask := LVIF_TEXT;
    pszText := PChar(integer(Buff) + SizeOf(pItem) * 4);
    cchTextMax := Length(Edit1.Text)+1;
  end;
  WriteProcessMemory(PRC, Buff, @pItem, Sizeof(pItem), R);
  WriteProcessMemory(PRC, PChar(integer(Buff) + SizeOf(pItem) * 4),
  PChar(Edit1.Text), Length(Edit1.Text)+1, R);
  SendMessage(hwnd,LVM_INSERTITEM,0,LongInt(Buff));
  VirtualFreeEx(PRC, Buff, 0, MEM_RELEASE);
  CloseHandle(PRC);

end;

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 209
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
VirtualProtectEx
2008-4-17 13:49
0
游客
登录 | 注册 方可回帖
返回
//