Trao đổi với tôi

http://www.buidao.com

4/17/10

[Programming] EnumModule

The Demo picture:



View the import Code:

/*---------------------------------------------------
*File: EnumModule.cpp
*Effect: 利用VirtualQueryEx枚举模块信息
*Edit: Huai_Huai
*Page: http://www.520160.com
*Date: 2005.11.24
*Compile by VC++6.0 on Winxp sp2
----------------------------------------------------*/

#include
#include

#include "resource.h"

BOOL EnumModule(HWND hwnd,DWORD pID)
{
BOOL fok=FALSE;
HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,
FALSE,pID);

MEMORY_BASIC_INFORMATION mbi;
PBYTE pAddress=NULL;
char szBuf[MAX_PATH*100]={0};

while(VirtualQueryEx(hProcess,pAddress,&mbi,sizeof(mbi))==sizeof(mbi))
{
int nLen=0;
char szModName[MAX_PATH]={0};
if((mbi.AllocationBase!=mbi.BaseAddress) || (mbi.State==MEM_FREE))
nLen=0;
else
nLen=GetModuleFileName((HINSTANCE)mbi.AllocationBase,szModName,MAX_PATH);

if(nLen>0)
{
wsprintf(strchr(szBuf,0),"\n%p-%s",
mbi.AllocationBase,szModName);
SendMessage(GetDlgItem(hwnd,IDC_LIST1),LB_ADDSTRING,0,(LPARAM)szModName);
}
pAddress+=mbi.RegionSize;
fok=TRUE;

}
return(fok);
}


void Dlg_OnCommand(HWND hwnd,UINT wNotifyCode,int wID,HWND hwndCtl)
{
switch(wID)
{
case IDCANCEL:
EndDialog(hwnd,wID);
break;
case IDC_BUTTON2:
DWORD pID=GetDlgItemInt(hwnd,IDC_EDIT2,NULL,FALSE);
if(pID==0)
pID=GetCurrentProcessId();
SendMessage(GetDlgItem(hwnd,IDC_LIST1),LB_RESETCONTENT,0,0);
EnumModule(hwnd,pID);
}
}

BOOL Dlg_OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
return(TRUE);
}

BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
SetWindowLong(hwndDlg,DWL_MSGRESULT,(LONG)Dlg_OnInitDialog(hwndDlg,(HWND)wParam,lParam));
case WM_COMMAND:
Dlg_OnCommand(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
break;
}
return(FALSE);
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DialogProc);
return (0);
}


Download the Project:

下载文件 点击下载此文件

reflink: http://www.simbafireworks.com/huaihuai/blog/article.asp?id=105