title: Upgrading C code to VB.NET - Unioned Structures
body: <p>I am trying to upgrade the btrieve code written by Jim Kyle in the early 90's to VB.NET and am running into a problem with unioned structures.  The old C code is as follows:</p>
  
  <pre><code>    typedef struct {
        union {
          struct {
            PGPTR   PgSeq;    // 00 - page number
            int     Usage;    // 04 - match with usage count
            int     Version;  // 06 - version code, &lt;0 if owned
          } v5;
          struct {
            int     RecSig;   // 00 - 'FC'
            int     SeqNbr;   // 02 - always binary zeroes
            long    Usage;    // 04 - usage count
          } v6;
        } r1;
        int     PagSize;  // 08 - in bytes
      } FCRTOP;
  </code></pre>
  
  <p>So far, I had:</p>
  
  <pre><code>    &lt;StructLayout(LayoutKind.Explicit)&gt; _
  Structure FCRTOP
      &lt;FieldOffset(0)&gt; Public PgSeq As PGPTR
      &lt;FieldOffset(4)&gt; Public Usage As Short
      &lt;FieldOffset(6)&gt; Public Version As Short
  
      &lt;FieldOffset(0)&gt; Public RecSig As Short
      &lt;FieldOffset(2)&gt; Public SeqNbr As Short
      &lt;FieldOffset(4)&gt; Public Usage As Integer
  End Structure
  </code></pre>
  
  <p>One issue I am running into is that VB.NET doesnt like two struct variables with the same name (Usage).  What am I missing to group the overlapping fields with a unique struct name as is done in the C example (v5 and v6)?</p>
  
  <p>Thanks for any help!</p>