'获取内存结构信息，返回结构数量，数组下标从 1 开始
'Type _MEMORY_BASIC_INFORMATION
'    BaseAddress as PVOID           '基地址
'    AllocationBase as PVOID
'    AllocationProtect as DWord
'    RegionSize as SIZE_T_         '页面大小
'    State as DWord
'    Protect as DWord              '页面属性2
'    as DWord Type
'End Type
#Include Once "win/winnt.bi"
Function MemStrInfo(jID as DWord, JG() as MEMORY_BASIC_INFORMATION) as Long  '  内存结构信息
   
   Dim xID as HANDLE ' 储存进程句柄
   Dim Ba as UInteger, Info as MEMORY_BASIC_INFORMATION, Bb as UInteger
   Dim  as  Integer  Ee,I
   xID = OpenProcess(&H1F0FFF, False, jID)
   If xID = 0 Then
      Function = 0
      Exit Function
   End If
   
   Ee = 0
   Ba = &H10000
   
   For i = 1 To 10000
      If VirtualQueryEx(xID, Cast(LPCVOID, Ba), @Info, SizeOf(MEMORY_BASIC_INFORMATION)) = 0 Then Exit For
      If Info.Type <> 0 Then
         If Info.Protect = &H2 Or Info.Protect = &H4 Or Info.Protect = &H8 _
            Or Info.Protect = &H10 Or Info.Protect = &H20 Or Info.Protect = &H40 _
            Or Info.Protect = &H80 Or Info.Protect = &H200 Or Info.Protect = &H400 _
            Then
               Ee = Ee + 1
            ReDim Preserve Jg(Ee)
            JG(ee) = info
            'jg(Ee).Address=Info.BaseAddress                 '          Info.基地址
            'jg(Ee).mSize=Info.RegionSize                   '结构_M(Ee).长度 = Info.页面大小
            'jg(Ee).Protect=Info.Protect                   '结构_M(Ee).类型 = Info.页面属性2
         End If
      End If
      Bb = Ba
      Ba = Cast(UInteger, Info.BaseAddress) + Info.RegionSize + 1
      If Bb = Ba Then Exit For
   Next
   CloseHandle xID
   
   Function = Ee
   
End Function
