实用的内存块操作类(vb源码)
来源:互联网 发布:java 反射调用方法 编辑:程序博客网 时间:2024/05/16 01:08
Option Explicit
Private Declare Function VirtualAlloc Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFree Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function VirtualLock Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long) As Long
Private Declare Function VirtualUnlock Lib "kernel32" (ByVal lpAddress As Long, ByVal dwSize As Long) As Long
Private Declare Function IsBadReadPtr Lib "kernel32" (ByVal lp As Long, ByVal ucb As Long) As Long
Private Declare Function IsBadWritePtr Lib "kernel32" (ByVal lp As Long, ByVal ucb As Long) As Long
Private Declare Function IsBadStringPtr Lib "kernel32" Alias "IsBadStringPtrA" (ByVal lpsz As Long, ByVal ucchMax As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpStringDest As String, ByVal lpStringSrc As Long) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByVal pDest As Long, ByVal pSrc As Long, ByVal ByteLen As Long)
Private Const MEM_DECOMMIT = &H4000
Private Const MEM_RELEASE = &H8000
Private Const MEM_COMMIT = &H1000
Private Const PAGE_EXECUTE_READWRITE = &H40
Private m_Handle As Long
Public Property Get Handle() As Long
Handle = m_Handle
End Property
'分配内存
Public Sub Allocate(ByVal lCount As Long)
Call Release
m_Handle = VirtualAlloc(ByVal 0&, lCount, MEM_COMMIT, PAGE_EXECUTE_READWRITE)
VirtualLock m_Handle, lCount
End Sub
'读取
Public Sub ReadFromPointer(ByVal hWritePointer As Long, ByVal lLength As Long)
If IsBadWritePtr(hWritePointer, lLength) = 0 And IsBadReadPtr(Handle, lLength) = 0 Then
CopyMemory hWritePointer, Handle, lLength
End If
End Sub
'写入
Public Sub WriteToPointer(ByVal hReadPointer As Long, ByVal lLength As Long)
If IsBadReadPtr(hReadPointer, lLength) = 0 And IsBadWritePtr(Handle, lLength) = 0 Then
CopyMemory Handle, hReadPointer, lLength
End If
End Sub
'释放内存
Public Sub Release()
Dim lLength As Long
If m_Handle <> 0 Then
VirtualUnlock m_Handle, lLength
VirtualFree m_Handle, lLength, MEM_DECOMMIT
VirtualFree m_Handle, 0, MEM_RELEASE
m_Handle = 0
End If
End Sub
Private Sub Class_Terminate()
Call Release
End Sub
- 实用的内存块操作类(vb源码)
- 实用的内存块操作类(vb源码)
- 实用的内存块操作类(vb源码)
- [VB.NET源码]操作EMAIL的类
- vb操作内存
- 固定尺寸内存块的缓冲队列类及C++实现源码
- memblkA 最简单的内存模拟块设备 源码
- [VB.NET源码]读写Excel的操作应用
- 一个简单实用的内存池类
- 共享内存操作类(C#源码)
- 共享内存操作类(C#源码)
- 共享内存操作类(C#源码)
- 共享内存操作类(C#源码)
- C#共享内存操作类(含源码)
- 共享内存操作类(C#源码)[转]
- 共享内存操作类(C#源码)
- 共享内存操作类(C#源码)
- 共享内存操作类(C#源码)
- 精品网址整理——计算机类学习视频资料
- UML日记-6类图的复合聚合关联关系
- 如何在C#中使用全局鼠标、键盘Hook
- vs.2005安装部署中的卸载
- 较为全面的程序部署
- 实用的内存块操作类(vb源码)
- 如何在C#中使用全局鼠标、键盘Hook
- css 十大密技
- 关于"sharepoint Portal Server2003深入指南"的读书笔记--2006年10月20 星期五 天气:晴 地点:成都
- C#.Net的全局键盘钩子(Hook)技术
- 在 ASP.NET 2.0 中上载文件
- ASP.NET 网页介绍
- Windows中的名言警句??
- Excel,Pdf,Xml 文件操作(一)