Can not read memory block allowed by VB
Posted: Mon Sep 21, 2009 1:25 pm
Hello at all
I have found this genius code of Stefan Savev who do a thing that it's normally not the works of VB
Create block memory and read in it
I just return the adress of pointer but not the value 10
VB code
Code of complex DLL
But obviously KCC try to read the memory block with PB and can not 
Someone know why ???
Good day
I have found this genius code of Stefan Savev who do a thing that it's normally not the works of VB

Create block memory and read in it
I just return the adress of pointer but not the value 10

VB code
Code: Select all
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal dwFlags As Long, lpMem As Any) As Long
Private Declare Sub CopyMemoryWrite Lib "kernel32" Alias "RtlMoveMemory" (ByVal Destination As Long, Source As Any, ByVal Length As Long)
Private Declare Sub CopyMemoryRead Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, ByVal Source As Long, ByVal Length As Long)
Private Declare Function AccessMemory Lib "DllAllocationMemoire.dll" (PointeurAllocation As Long) As Long
Private Sub Form_Load()
Dim ptr As Long 'int * ptr;
Dim hHeap As Long
hHeap = GetProcessHeap()
ptr = HeapAlloc(hHeap, 0, 2) 'an integer in Visual Basic is 2 bytes
If ptr <> 0 Then
'memory was allocated
'do stuff
Dim i As Integer
i = 10
CopyMemoryWrite ptr, i, 2 ' an integer is two bytes
Dim j As Integer
CopyMemoryRead j, ptr, 2
MsgBox "The adress of ptr is " & CStr(ptr) & vbCrLf & "and the value is " & CStr(j)
HeapFree GetProcessHeap(), 0, ptr
End If
End Sub

Code: Select all
ProcedureDLL AccessMemory(*BSTR)
MessageRequester("", Str(PeekL(*BSTR)))
EndProcedure

Someone know why ???
Good day