How to move a intptr in vb.net 2003

  • Thread starter Thread starter Robert Dufour
  • Start date Start date
R

Robert Dufour

As a simple example starting with a memory pointer location I need to do 10
operations, (like copying 10 values to an array for instance), then when
that's done, move the pointer to the eleventh location so that I can then
use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
'Do something like getting 10 values from memory from this block,
initailly at ptr1
'next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 'Does not work
next x

How can you do this in vb.net 2003

Thanks for any help
Bob
 
Robert said:
As a simple example starting with a memory pointer location I need to do 10
operations, (like copying 10 values to an array for instance), then when
that's done, move the pointer to the eleventh location so that I can then
use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
'Do something like getting 10 values from memory from this block,
initailly at ptr1
'next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 'Does not work
next x

I'm not aware of support for pointer arithmetic with IntPtr's. Maybe
you can get by with manual incrementing of the pointer, but this needs
to be well thought out. Do you need to point to a position ten *bytes*
away or one ten *elements* away? If the former, you'll need to
consider the element's size. A call to
System.Runtime.InteropServices.Marshal would help in this case.

<aircode>
'ten *bytes* away
Ptr = New IntPtr(Ptr.ToInt64 + 10)

'ten *elements* away
Ptr = New IntPtr(Ptr.ToInt64 + 10 * _
System.Runtime.InteropServices.Marshal.SizeOf(ElementType))
</aircode>


HTH.

Regards,

Branco.
 
Hi Robert,

"ptr1 = Ptr1 + 10 'Does not work"

I don't have a whole bunch of experience with pointers in vb.net (only been
programming vb.net a few months now)
In C++ (bare with me here) Incrementing a pointer is going to move it along
as many bytes as the sizeof the datatype it is pointing / refering to, this
I do not think is the case with vb.net

I think that incrementing an IntPtr in .net is only going to make it walk
one byte forward in memory, so unless your array is of type "byte" or "char"
it is not going to be moving with the correct offset.

so lets say you are pointing to an array of integers (on 32 bit computer)
then

ptr1 = Ptr1 + 40

Or in other words:
ptr1 = ptr1 + 10 * dataTypeSize

Regards,

Mike
 
Sorry I have kind of repeated what you answered, your post was not visible
when I hit the reply group button.
 
Robert Dufour said:
As a simple example starting with a memory pointer location I need to do
10 operations, (like copying 10 values to an array for instance), then
when that's done, move the pointer to the eleventh location so that I can
then use the next ten values, etc
Dim Ptr1 as IntPtr
For x = 0 to 100
'Do something like getting 10 values from memory from this block,
initailly at ptr1
'next move the pointer to a new position 10 units so that I can pickup
the next 10 values
ptr1 = Ptr1 + 10 'Does not work
next x

How can you do this in vb.net 2003

In addition to the other replies, you can use the 'Marshal' class to
populate the array using data read from the memory location too.
 
Thanks to all, actually I'm trying to get my head around manipulating bytes
in bitmaps and copying from an old bitmap in rgb24 to a monochrome bitmap,
the samples of code I saw had things like intptr and I never used them
before. Never had to do any graphics before so I'm learning
Thanks
Bob
 
Robert said:
Thanks to all, actually I'm trying to get my head around manipulating bytes
in bitmaps and copying from an old bitmap in rgb24 to a monochrome bitmap,
<snip>

Maybe the GDI+ library can be used instead of trying to deal directly
with the bits... I remember once using BitBlt (from the Win32 gdi
library) to copy whatever bits I needed between bitmats of different
formats. I suppose GDI+ is capable of that much and more...

Regards,

Branco.
 
I thought so but I can't find a way to do it.
There's a lot of stuff out ther doing this, so it must be possible.
I'm just trying to understand how it can be done.
I only found one thing that worked Ok for what I needed to do and it was the
Universal document converter but that works as a printer driver, so a user
could go in and change settings on his machine and my program would be
screwed up.
Thats why I am trying to roll my own.
Basic problem is I'm too stupid to be able to make sense out of all the docs
out there and put it all together in a simple way thats gonna be easy to
maintain later.
Regards,
Bob
 
Thanks that's what I'm trying to use.
Bob
Herfried K. Wagner said:
In addition to the other replies, you can use the 'Marshal' class to
populate the array using data read from the memory location too.
 
Thanks Michael
In been doing a LOT of reading up on all this and I WILL get it.
Gonna keep plugging at it,

Regards,
Bob
 
Back
Top