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 / Languages / C# / October 2007

Tip: Looking for answers? Try searching our database.

Marshelling help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
colin - 31 Oct 2007 18:55 GMT
Hi,
well ive written some code wich iterates through all the fields in
my data structures wich I need to format to/from a file
(wich has a complicated format)
and I can identify some simple structures that are packed and sequenctial
that I can
just binary copy the whole structure,

however I cant figure out how to get round the problems imposed in c#:-

I pass the structure to the function as an object ref,
but i cant then take the address of an object as it complains,
so I cant just simply copy it with pointers in an unsafe+fixed code section.

but when I use the marsheling services such as
Masrhal.PtrToStructure(fileSourceIntPtr,destObj)
it complains that it cant do this on destObj as it is a value type.
it wont let me pass it as a ref either.

it all seems to work ok for clases but that is too much of a  limitation.

so is there any way to get the binary data from a file
copied into a packed struct when you only have a object ref to it ?

ive been looking for ages at the marshelling stuff and ive started to get
crossed eyes lol

thanks
Colin =^.^=
Mattias Sjögren - 31 Oct 2007 22:33 GMT
>but when I use the marsheling services such as
>Masrhal.PtrToStructure(fileSourceIntPtr,destObj)
>it complains that it cant do this on destObj as it is a value type.
>it wont let me pass it as a ref either.

Use the other PtrToStructure overload

destObj = Marshal.PtrToStructure(fileSourceIntPtr,
typeof(YourStruct));

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

colin - 01 Nov 2007 00:11 GMT
> >but when I use the marsheling services such as
>>Masrhal.PtrToStructure(fileSourceIntPtr,destObj)
[quoted text clipped - 5 lines]
> destObj = Marshal.PtrToStructure(fileSourceIntPtr,
> typeof(YourStruct));

wow cool thanks, i missed that one somehow.
does it make a newly alocated block of memory then copy it to the structure?
or is it cool enough to just use the destination ?

itl prob be probably ok either way.

Colin =^.^=

Rate this thread:







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.