|
-
Oct 20th, 2007, 01:57 AM
#1
-
Oct 20th, 2007, 02:15 AM
#2
Re: [2.0] getting the first byte of a structure? HELP!
You could either use unsafe code if you really must have a genuine pointer, or else the Marshal.StructureToPtr method should do the trick.
-
Oct 20th, 2007, 02:47 AM
#3
Re: [2.0] getting the first byte of a structure? HELP!
 Originally Posted by jmcilhinney
You could either use unsafe code if you really must have a genuine pointer, or else the Marshal.StructureToPtr method should do the trick.
Hi! thanks man! 
I looked at that marshal function,
i kinda lied actually, i needed a "ref byte" not a byte pointer, so I passed in the first field in the structure and it works fine....
curious though, in an unsafe context how would you convert the structure to a byte* ?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Oct 20th, 2007, 03:06 AM
#4
Re: [2.0] getting the first byte of a structure? HELP!
I've actually never written any unsafe code in C# but I would expect it would be something like:That would do the trick in C++, although C# may have an issue with converting the address of one type to a pointer of another type. You may have to cast like this:
CSharp Code:
byte* p = (byte*)&myStructure;
Also, I'm not 100% sure that the addressof operator (&) from C/C++ has carried over, but I'm guessing it has.
Edit: Just checked and that second code snippet does the trick.
Last edited by jmcilhinney; Oct 20th, 2007 at 03:20 AM.
-
Oct 20th, 2007, 01:15 PM
#5
Re: [2.0] getting the first byte of a structure? HELP!
 Originally Posted by jmcilhinney
I've actually never written any unsafe code in C# but I would expect it would be something like: That would do the trick in C++, although C# may have an issue with converting the address of one type to a pointer of another type. You may have to cast like this:
CSharp Code:
byte* p = (byte*)&myStructure;
Also, I'm not 100% sure that the addressof operator (&) from C/C++ has carried over, but I'm guessing it has.
Edit: Just checked and that second code snippet does the trick.
and why did i never think of that? 
thanks
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|