![]() ![]() Public Property Get MemLong(ByVal memAddress As Long) As LongĭeRefMem m_remoteMemory, memAddress, vbLong Public Property Get MemLong(ByVal memAddress As LongPtr) As Long 'Read/Write 4 Bytes (Long) from/to memory Public Property Let MemInt(ByVal memAddress As Long, ByVal newValue As Integer) Public Property Let MemInt(ByVal memAddress As LongPtr, ByVal newValue As Integer) Public Property Get MemInt(ByVal memAddress As Long) As IntegerĭeRefMem m_remoteMemory, memAddress, vbInteger Public Property Get MemInt(ByVal memAddress As LongPtr) As Integer 'Read/Write 2 Bytes (Integer) from/to memory Public Property Let MemByte(ByVal memAddress As Long, ByVal newValue As Byte) Public Property Let MemByte(ByVal memAddress As LongPtr, ByVal newValue As Byte) Public Property Get MemByte(ByVal memAddress As Long) As ByteĭeRefMem m_remoteMemory, memAddress, vbByte Public Property Get MemByte(ByVal memAddress As LongPtr) As Byte IsInitialized As Boolean 'In case state is lost Public Const vbLongPtr As Long = vbLongLong Public Const vbLongLong As Long = 20 'Apparently missing for 圆4 on Mac Public Declare Function VarPtrArray Lib "msvbvm60.dll" Alias "VarPtr" (ByRef ptr() As Any) As Long Public Declare PtrSafe Function VarPtrArray Lib "VBE7.dll" Alias "VarPtr" (ByRef ptr() As Any) As LongPtr Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As Long) Public Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, source As Any, ByVal Length As LongPtr) Public Declare Function CopyMemory Lib "/usr/lib/libc.dylib" Alias "memmove" (Destination As Any, source As Any, ByVal Length As Long) As Long Public Declare PtrSafe Function CopyMemory Lib "/usr/lib/libc.dylib" Alias "memmove" (Destination As Any, source As Any, ByVal Length As LongPtr) As LongPtr Private Const MODULE_NAME As String = "LibMemory" ![]() LibMemory standard module: Option Explicit The full module with more explanations and also demos are available on GitHub at VBA-MemoryTools. ![]() These 2 Variants allow remote read/write of memory. In short, I am using 2 Variants that have the VT_BYREF flag set inside the 2 Bytes holding the VarType. So, I created a couple of properties (Get/Let) called MemByte, MemInt, MemLong and MemLongPtr using the same ByRef technique that I've used in the WeakReference repository. Since I did not want to use references to msvbvm60.dll which is not available on most of my machines, I decided to create something similar with the GetMemX and PutMemX methods available in the mentioned dll. millions of times).Įven without the issue mentioned above, CopyMemory API is slower than other alternatives. Regardless of why the API is much slower, it is unusable if the operations involving the API need to run many times (e.g. In this SO question is seems that Windows Defender is the cause of slowness. I did do a Windows Update lately and maybe that is why. For example on one of my machines (圆4 Windows and x32 Office) the CopyMemory API is running about 600 times slower than a month ago. I've been quite annoyed lately by the fact that the CopyMemory API ( RtlMoveMemory on Windows and MemMove on Mac) is running much slower than it used to, on certain computers. ![]()
0 Comments
Leave a Reply. |