hur.cn - 华软网

 热门搜索

小程序,一直吃内存,求教

  作者:未知    来源:网络    更新时间:2011/4/15
int CHWmonitor::GetRootClass(CStringArray* p)
{
HWND hwnd;
CString text;
int index=1;
bool isP=false;
hwnd= ::FindWindow(NULL,"CPUID Hardware Monitor");
hwnd=::FindWindowEx(hwnd,NULL,"AfxFrameOrView80su",NULL);
hwnd=::FindWindowEx(hwnd,NULL,"SysTreeView32",NULL);
const int bufferLength = 4000; 
DWORD processId = NULL; 
LPTVITEM item = (LPTVITEM)new BYTE[bufferLength]; 
GetWindowThreadProcessId(hwnd,&processId); 
HANDLE process = ::OpenProcess(PROCESS_VM_OPERATION |PROCESS_VM_READ |PROCESS_VM_WRITE,false,processId); 
PVOID buffer = VirtualAllocEx(process,NULL,bufferLength,MEM_COMMIT,PAGE_READWRITE); 
item->mask = TVIF_TEXT; 
item->cchTextMax = 512; 
item->pszText = LPTSTR((PBYTE)buffer+sizeof(TVITEM)); 
item->hItem = (HTREEITEM)::SendMessage(hwnd,TVM_GETNEXTITEM,TVGN_ROOT,0); 
while(item->hItem) 

::SendMessage(hwnd,TVM_SELECTITEM,TVGN_CARET,(long)item->hItem); 
WriteProcessMemory(process,buffer,item,sizeof(TVITEM),NULL); 
::SendMessage(hwnd,TVM_GETITEM,0,(LPARAM)buffer); 
ReadProcessMemory(process,buffer,item,bufferLength,NULL); 
text = (LPTSTR)((PBYTE)item+sizeof(TVITEM)); 
//MessageBox(text);
if(index!=1)
{
::SendMessage(hwnd,TVM_EXPAND,TVE_COLLAPSE,(long)item->hItem);
}
else
index++;
item->hItem = (HTREEITEM)::SendMessage(hwnd,TVM_GETNEXTITEM,TVGN_NEXTVISIBLE,(long)item->hItem); 
p->Add(text);

int iRes=p->GetCount()-1;
VirtualFreeEx(process,buffer,0,MEM_RELEASE);
return iRes;
}
---华软 网友回答---
LPTVITEM item = (LPTVITEM)new BYTE[bufferLength];  
要记得
delete [] item ;
---华软网友回复---
楼上滴,谢谢,我测试下。      
华软声明:本内容来自网络,如有侵犯您版权请来信指出,本站立即删除。