Hi,
It is especially challenging to do interop marshalling with the Win32 API
BackupRead, because it returns a byte array that can be interpreted in
several different ways.
My specific question is how to use the Marshal functions such as
PtrToStructure when the unmanaged structure that I am after can appear
anywhere inside a large buffer. I need to be able to use a pointer PLUS
offset to reach the WIN32_STREAM_ID structure, but the Marshal.PtrToStructure
function has no overload which accepts an offset.
What are the options for doing pointer arithmetic with IntPtr's WITHOUT
using unsafe code??
Thank you very much,
Rich S.
Dmytro Lapshyn [MVP] - 18 Nov 2005 16:13 GMT
Hi,
You can do a hack like this:
int ptr = myIntPtr.ToInt32();
ptr += ofset;
IntPtr myOffsetPtr = new IntPtr(ptr);

Signature
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
> Hi,
>
[quoted text clipped - 14 lines]
> Thank you very much,
> Rich S.
Mattias Sjögren - 18 Nov 2005 16:16 GMT
> What are the options for doing pointer arithmetic with IntPtr's WITHOUT
> using unsafe code??
Cast to int/long, do your arithmetic, and then cast back. It's not a
beautiful solution but I don't know any better. It would sure be nice if C#
had build in arithmetic support for (U)IntPtr too.
Mattias