Using FieldOffsetAttribute in CF

  • Thread starter Thread starter James Grennan via .NET 247
  • Start date Start date
J

James Grennan via .NET 247

I wonder if anyone could help me with this code.

I found some code from Microsoft to ping a host written in VB.NET and it works perfect in the standard framework.
(See http://support.microsoft.com/default.aspx?scid=kb;en-us;828993 )

I want to use it in the compact framework, but I get a compile error.
The CF.NET does not seem to recognise the FieldOffset Attribute
I don?t have enough experience in Marshalling to fixed this.

The code with the problem is :

<StructLayout(LayoutKind.Explicit)> Structure UNION_INT16
<FieldOffset(0)> Dim lsb As Byte
<FieldOffset(1)> Dim msb As Byte
<FieldOffset(0)> Dim w16 As Short

End Structure

<StructLayout(LayoutKind.Explicit)> Structure UNION_INT32
<FieldOffset(0)> Dim lsw As UNION_INT16
<FieldOffset(2)> Dim msw As UNION_INT16 '
<FieldOffset(0)> Dim w32 As Integer
End Structure
 
In compact framework v1 there is no support for explicit layout. In this
particular case just use a Integer type (or Int16 for a 16-bit structure)
and bit arithmetics to set/get parts of it:

lsb = Value16 AND &HFF
msb = Value16 Shr 8

lsw = Value32 AND &HFFFF
msw = Value32 Shr 16

For ping sample that works with CE.NET and compact framework take a look at
http://www.alexfeinman.com/download.asp?doc=ping.zip
It's in C#. I have a VB version converted by Milosz Weckowski of
www.playseven.com, but I cannot post it here without his permission

--
Alex Feinman
---
Visit http://www.opennetcf.org
James Grennan via .NET 247 said:
I wonder if anyone could help me with this code.

I found some code from Microsoft to ping a host written in VB.NET and it
works perfect in the standard framework.
 
Back
Top