|
-
Jan 24th, 2006, 03:32 AM
#1
Thread Starter
New Member
Question about Visual Basic 6 and memory buffers
Hello,
I have a DLL written in C++: one of its functions returns a pointer to a
memory buffer in form of a long value (32 bits); when calling this function
from within Visual Basic, which is the best way to let Visual Basic access
this existing buffer?
I know that Visual Basic lets define a memory buffers like this:
Dim buffer() As Byte
how can I initialize this buffer using the long value returned by the DLL?
Thanks in advance and Kind Regards
Severino
-
Jan 24th, 2006, 06:54 AM
#2
Re: Question about Visual Basic 6 and memory buffers
It's a bit hard to try and access it as such so your best bet is to use RtlMoveMemory to move the buffer contents into your VB buffer. Either that or pass a pointer to your VB buffer in the first place.
VB Code:
Declare Sub RtlMoveMemory Lib "kernel32" ( _
ByRef lpvDest As Any, _
ByRef lpvSrc As Any, _
ByVal cbLen As Long _
)
-
Jan 24th, 2006, 07:16 AM
#3
Re: Question about Visual Basic 6 and memory buffers
You might be interested about the trick used in this code: InStrCount. Basically the code makes a fake SAFEARRAYHEADER, assings this to an Integer array using CopyMemory (RtlMoveMemory) and then we could virtually read memory from anywhere.
Noticeable is that BufStrHeader(1) = 2 tells the array to be used is an integer array (two bytes per item). Change to 1 and it works with a byte array.
And then the warning: doing this is pretty dangerous, so save often and don't blame us if you destroy your computer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|