【新提醒】獲取并顯示當(dāng)前內(nèi)存使用情況(支持4G以上內(nèi)存),Win32匯編語(yǔ)言案例解析,典型案例解析(VIP免費(fèi)),魚(yú)C論壇
該系列案例解析按級(jí)別類(lèi)別排列,如:
- [基礎(chǔ)知識(shí)]: 類(lèi)別為基礎(chǔ)知識(shí)
- 1.2: 級(jí)別,第一個(gè)1表示屬于最簡(jiǎn)單級(jí)別,后邊的2僅為案例的序數(shù)(不代表難度增加(⊙o⊙)哦)
要求:獲取并顯示當(dāng)前內(nèi)存使用情況(支持4G以上內(nèi)存)
演示截圖:
代碼及詳細(xì)注釋?zhuān)?/font>
本帖隱藏的內(nèi)容
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; by 小甲魚(yú), http://www.fishc.com
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; MemInfo.asm
- ; 獲取并顯示當(dāng)前內(nèi)存使用情況(支持4G以上內(nèi)存)
- ; 對(duì)于4G以上的內(nèi)存獲取,使用 GlobalMemoryStatus 會(huì)有很多問(wèn)題出現(xiàn)
- ; 這時(shí)候我們要用 GlobalMemoryStatusEx
- ; 注意,GlobalMemoryStatusEx 需要的 MEMORYSTATUSEX 結(jié)構(gòu)我們要自己定義
- ; ullTotalPhys 等成員是64位的,我們要自己定義
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 使用 nmake 或下列命令進(jìn)行編譯和鏈接:
- ; ml /c /coff MemInfo.asm
- ; rc MemInfo.rc
- ; Link /subsystem:windows MemInfo.obj MemInfo.res
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .386
- .model flat, stdcall
- option casemap :none
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; Include 文件定義
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- include windows.inc
- include user32.inc
- includelib user32.lib
- include kernel32.inc
- includelib kernel32.lib
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; Equ 等值定義
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ICO_MAIN equ 1000
- DLG_MAIN equ 100
- IDC_INFO equ 101
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 數(shù)據(jù)段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .data?
- hInstance dd ?
- hWinMain dd ?
- .const
- szInfo db '物理內(nèi)存總數(shù) %I64d KB',0dh,0ah
- db '空閑物理內(nèi)存 %I64d KB',0dh,0ah
- db '虛擬內(nèi)存總數(shù) %I64d KB',0dh,0ah
- db '空閑虛擬內(nèi)存 %I64d KB',0dh,0ah
- db '已用內(nèi)存比例 %d%%',0dh,0ah
- db '———————————————',0dh,0ah
- db '用戶地址空間總數(shù) %I64d KB',0dh,0ah
- db '用戶可用地址空間 %I64d KB',0dh,0ah,0
-
- DWORDDWORD STRUCT
- lowDWORD DWORD ?
- highDWORD DWORD ?
- DWORDDWORD ENDS
- MEMORYSTATUSEX STRUCT
- dwLength DWORD ?
- dwMemoryLoad DWORD ?
- ullTotalPhys DWORDDWORD <>
- ullAvailPhys DWORDDWORD <>
- ullTotalPageFile DWORDDWORD <>
- ullAvailPageFile DWORDDWORD <>
- ullTotalVirtual DWORDDWORD <>
- ullAvailVirtual DWORDDWORD <>
- ullAvailExtendedVirtual DWORDDWORD <>
- MEMORYSTATUSEX ENDS
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; 代碼段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .code
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ; _Div1024這個(gè)函數(shù)干嘛呢?就是將大數(shù)除以1024,相當(dāng)于右移10位
- ; 兩個(gè)參數(shù)通過(guò)傳址調(diào)用,醬紫省下了多余的變量
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- _Div1024 proc uses esi edi _lowDWORD:DWORD, _highDWORD:DWORD
- mov esi, _lowDWORD
- mov edi, _highDWORD
- mov eax, DWORD ptr [esi]
- mov edx, DWORD ptr [edi]
- shr eax, 10
- mov ecx, edx
- shl ecx, 22
- or eax, ecx
- mov DWORD ptr [esi], eax
- shr edx, 10
- mov DWORD ptr [edi], edx
-
- xor eax, eax
-
- ret
- _Div1024 endp
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- _GetMemInfo proc
- local @stMemInfo:MEMORYSTATUSEX ; GlobalMemoryStatusEx需要
- local @szBuffer[1024]:byte
- mov @stMemInfo.dwLength,sizeof @stMemInfo
-
- invoke GlobalMemoryStatusEx,addr @stMemInfo
-
- invoke _Div1024, addr @stMemInfo.ullTotalPhys.lowDWORD, addr @stMemInfo.ullTotalPhys.highDWORD
- invoke _Div1024, addr @stMemInfo.ullAvailPhys.lowDWORD, addr @stMemInfo.ullAvailPhys.highDWORD
- invoke _Div1024, addr @stMemInfo.ullTotalPageFile.lowDWORD, addr @stMemInfo.ullTotalPageFile.highDWORD
- invoke _Div1024, addr @stMemInfo.ullAvailPageFile.lowDWORD, addr @stMemInfo.ullAvailPageFile.highDWORD
- invoke _Div1024, addr @stMemInfo.ullTotalVirtual.lowDWORD, addr @stMemInfo.ullTotalVirtual.highDWORD
- invoke _Div1024, addr @stMemInfo.ullAvailVirtual.lowDWORD, addr @stMemInfo.ullAvailVirtual.highDWORD
-
- invoke wsprintf,addr @szBuffer,addr szInfo,\
- @stMemInfo.ullTotalPhys,@stMemInfo.ullAvailPhys,\
- @stMemInfo.ullTotalPageFile,@stMemInfo.ullAvailPageFile,\
- @stMemInfo.dwMemoryLoad,\
- @stMemInfo.ullTotalVirtual,@stMemInfo.ullAvailVirtual
-
- invoke SetDlgItemText,hWinMain,IDC_INFO,addr @szBuffer
-
- ret
- _GetMemInfo endp
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- _ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
- mov eax,wMsg
- .if eax == WM_TIMER
- call _GetMemInfo
- .elseif eax == WM_CLOSE
- invoke KillTimer,hWnd,1
- invoke EndDialog,hWnd,NULL
- ;********************************************************************
- .elseif eax == WM_INITDIALOG
- push hWnd
- pop hWinMain
- invoke LoadIcon,hInstance,ICO_MAIN
- invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
- invoke SetTimer,hWnd,1,1000,NULL
- call _GetMemInfo
- ;********************************************************************
- .else
- mov eax,FALSE
- ret
- .endif
- mov eax,TRUE
- ret
- _ProcDlgMain endp
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- start:
- invoke GetModuleHandle,NULL
- mov hInstance,eax
- invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
- invoke ExitProcess,NULL
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- end start
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。