重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
vb.net 有专门的托盘图标控件 在工具箱里直接添加一个就可以了 两行代码即可
成都创新互联-专业网站定制、快速模板网站建设、高性价比河间网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式河间网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖河间地区。费用合理售后完善,10年实体公司更值得信赖。
NotifyIcon1.Icon = Me.Icon
NotifyIcon1.Visible = True
要有效的减少程序的内存占用量,从本质上来讲,就是要提高算法的空间效率,但提高空间效率的同时,必然就降低时间效率,这是任何一本教科书都会说的。
比如排序,采用原地置换方式的算法通常都没有在新空间中构造序列的算法快。
无论是要提高空间效率或是时间效率,其关键都在于算法的设计。当然,从系统分析的角度来讲,采用良好的设计模式可以避免很多不必要的麻烦 ^o^
这说明你调用 API 传参存在问题。
首先有没有设置结构体内存对齐?
[StructLayout(LayoutKind.Sequential)] 加了吗?
COLORREF 不要用 Color 代替,用 int 代替
TCHAR cfFaceName[32] 定义为 Byte 数组也可以,带在传参前,必须初始化为 32 个长度
Imports System.Runtime.InteropServices
Public Class MemoryEditor
Inherits WINAPI.NativeMethods
Private phwnd As IntPtr
Private Buffer As Byte()
Private BytesRead As IntPtr
Private BytesWrite As IntPtr
''' summary创建内存编辑器/summary
''' param name="processHwnd"进程句柄/param
Sub New(processHwnd As IntPtr)
Me.phwnd = processHwnd
End Sub
''' summary根据指定偏移量读取内存基址/summary
''' param name="addr"内存地址/param
''' param name="offsets"偏移量数组/param
Public Function ReadBaseAddress(addr As IntPtr, offsets() As Integer) As IntPtr
Dim address As IntPtr = ReadMemoryToInteger(addr)
For Each offset As Integer In offsets
address = address.ToInt32 + offset
address = ReadMemoryToInteger(address)
If address = IntPtr.Zero Then
Dim errInfo As String = "内存偏移量[" Hex(offset) "]错误!"
Throw New Exception(errInfo)
End If
Next
Return address
End Function
''' summary读取4字节内存数值/summary
''' param name="addr"内存地址/param
Public Function ReadMemoryToInteger(addr As IntPtr) As Integer
Buffer = New Byte(3) {}
ReadProcessMemory(phwnd, addr, Buffer, 4, BytesRead)
Return BitConverter.ToInt32(Buffer, 0)
End Function
''' summary读取4字节内存数组/summary
''' param name="addr"内存地址/param
Public Function ReadMemoryToBytes(addr As IntPtr) As Byte()
Buffer = New Byte(3) {}
ReadProcessMemory(phwnd, addr, Buffer, 4, BytesRead)
Return Buffer
End Function
''' summary将内存值数组写入指定地址/summary
''' param name="addr"内存地址/param
''' param name="buffer"内存值数组/param
Public Function WriteMemoryByBytes(addr As IntPtr, buffer As Byte()) As Boolean
Return WriteProcessMemory(phwnd, addr, buffer, buffer.Length, BytesWrite)
End Function
End Class
Namespace WINAPI
Public MustInherit Class NativeMethods
DllImport("kernel32.dll", SetLastError:=True) _
Public Shared Function ReadProcessMemory(ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
Out() ByVal lpBuffer() As Byte, _
ByVal dwSize As Integer, _
ByRef lpBytesRead As Integer) As Boolean
End Function
DllImport("kernel32.dll", SetLastError:=True) _
Public Shared Function WriteProcessMemory(ByVal hProcess As IntPtr, _
ByVal lpBaseAddress As IntPtr, _
ByVal lpBuffer As Byte(), _
ByVal nSize As Integer, _
Out() ByRef lpBytesWritten As IntPtr) As Boolean
End Function
End Class
End Namespace
是不是内存读写代码有问题!用上面的代码试试,我以前写的;
调用方法:
Dim mem As New MemoryEditor(进程句柄)
Dim offsets As Integer() = {H1, H2, H3} '{一级基址,二级基址,三级基址}
Dim baseaddr As IntPtr = mem.ReadBaseAddress(内存地址, offsets)
Dim value As Integer = mem.ReadMemoryToInteger(baseaddr)