hello
I need send byte value to copymemory Function
…
Soft Declare Sub CopyMemory Lib “kernel32” Alias “RtlMoveMemory” ( Destination As Byte , Source As WString , Length As Integer )
Dim Pt As Integer
Dim Data( ) As Byte
1 -
Call CopyMemory( Data( pt ) , “Xojo” , 4 )
2 -
Call CopyMemory( Data( pt ) + 4 , “Xojo” , 4 )
3 -
Call CopyMemory( Data( 0 ) , “Xojo” , 4 )
…
I converted Byte to MemoryBlock
1 -
Dim mb As New MemoryBlock( 1 )
mb.Byte( 0 ) = Data( Pt )
2 -
Dim mb As New MemoryBlock( UBound( Data ) + 1 )
For I As Integer = 0 To UBound( Data )
mb.Byte( I ) = Data( I )
Next I
but i have problem !!!
convert mb to
( Data( pt ) + 4 ) and ( Data( 0 ) )
Unless you’re dealing with memory not allocated by Xojo, I don’t see why you would want to use Win32’s CopyMemory function instead of Xojo’s built-in string and memory types.
That being said, the issue is that the source and destination arguments should be declared as Ptrs since they point to the memory locations. I would not use WString because CopyMemory doesn’t know about null terminators or multi-byte characters anyway.
For both the source and destination arguments (declared as Ptrs) pass in MemoryBlocks (and use MemoryBlock.Size instead of hard-coded byte counts.)
e.g.
Soft Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( Destination As Ptr , Source As Ptr , Length As Integer )
Dim source As MemoryBlock = "Xojo"
Dim length As Integer = source.Size
Dim destination As New MemoryBlock(length)
CopyMemory(destination, source, length)
Sory my English is bad …
I mean sending all this values
Data( Pt )
Data( Pt ) + 4
Data( 0 )
to Windows API
after converting Byte to MemoryBlock and passing to CopyMemory
Dim mb As New MemoryBlock( 1 )
mb.Byte( 0 ) = Data( Pt )
my problem is here
mb ’ OK
mb + 4 ’ Error
mb( 0 ) ’ !!!
VB Code
Call CopyMemory( Data( pt ) , X , X )
add 4 to Data( pt )
Call CopyMemory( Data( pt ) + 4 , X , X )
and Passing Data( 0 ) to api Function
Call WriteProcessMemory( X , X , Data( 0 ) , X , X )
are you trying to create a block of memory and populate it with some kind of 4 byte header?
eg
a Memoryblock of 10bytes
0123456789
needs to be
ABCD0123456789
You can just create a 4 byte memory block, and a 10 byte memory block
There is an override on the Add function so can literally just add these two together and the function returns a new (combined) memoryblock
Problem 1
VB
Call CopyMemory( Data( pt ) + 4 , X , X ) ’ work
Xojo
Call CopyMemory( Data( pt ).Byte + 4 , X , X ) ’ not work I can not pass Byte Value
Call CopyMemory( mb + 4 , X , X ) ’ Error
Problem 2
VB
Call WriteProcessMemory( X , X , Data( 0 ) , X , X ) ’ Work
Call WriteProcessMemory( X , X , 67 , X , X ) ’ VB Value
Xojo
Call WriteProcessMemory( X , X , Data( 0 ) , X , X ) ’ not work I can not pass Byte Value
Call WriteProcessMemory( X , X , mb , X , X ) ’ incorrect Value
Call WriteProcessMemory( X , X , 139 , X , X ) ’ Xojo Value