PeekW from Memory (VB Module)

Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by ricardo.

Hi,

Im succesffuly working with Bass.dll.
Now i can do almost everything but find a trouble to work with this kind of procedure (its in VB).
I receive a buffer and the length of the buffer in the parameters and need to read it word by word or float by float (i preffer word but its not important) do something with it and rite it back into memory.

See the example (parts in red are giving troubles)

Code: Select all

Public Sub Rotate(ByVal handle As Long, ByVal channel As Long, ByVal buffer As Long, ByVal length As Long, ByVal user As Long)
    Dim d() As Single, a As Long
    ReDim d(length / 4) As Single
    
    Call CopyMemory(d(0), ByVal buffer, length)
    
    For a = 0 To (length / 4) - 1 Step 2
        d(a) = d(a) * CSng(Abs(Sin(rotpos)))
        d(a + 1) = d(a + 1) * CSng(Abs(Cos(rotpos)))
        rotpos = fmod(rotpos + 0.00003, PI)
    Next a
    
    Call CopyMemory(ByVal buffer, d(0), length)
End Sub
The CopyMemory part i tried to do it by this way:

If OpenLibrary(1,"kernel32")
*CopyMemory = IsFunction(1,"RtlMoveMemory")
EndIf

And inside the procedure:

*Memory = AllocateMemory(0,length,0)
If *Memory
If CallFunctionFast(*CopyMemory,*Memory, buffer, length)
FreeMemory(0)
EndIf
EndIf

But crashes.. i tried CallFunctionFast(*CopyMemory,*Memory, @buffer, length) and crashes too.

I tried another way:

For i = 0 To length Step 4
ChD.w = PeekW(buffer + i)
ChI.w = PeekW(buffer + i + 2)
... do something
PokeW(buffer + i,ChD)
PokeW(buffer + i + 2,ChI)
Next i

Its dont crash but its like im not doing nothing... i dont heard anychanges.

Any idea?

Best Regards

Ricardo

Dont cry anymore...:)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
Originally posted by ricardo

If OpenLibrary(1,"kernel32")
*CopyMemory = IsFunction(1,"RtlMoveMemory")
EndIf
RtlMoveMemory is a kernel mode function (if I am getting it correctly), so user mode applications cannot use it.
I tried another way:

For i = 0 To length Step 4
ChD.w = PeekW(buffer + i)
ChI.w = PeekW(buffer + i + 2)
... do something
PokeW(buffer + i,ChD)
PokeW(buffer + i + 2,ChI)
Next i

Its dont crash but its like im not doing nothing... i dont heard anychanges.
Well, it looks correct, although you might want to change it to "For i=0 To length - 1 Step 4" otherwise you will perform one extra manipulation at the end of the loop.

You could also try the CopyMemory command from the memory library.


--
I used to be a nihilist but I don't believe in that any more.
(Win98first ed. + all updates, PB3.51, external editor)
Post Reply