Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

Ptr Arithmetic w/ Marshaller

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rich S. - 18 Nov 2005 10:20 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.