64-bit error with LayoutKind.Explicit

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andre de Ruiter
    New Member
    • Apr 2010
    • 1

    64-bit error with LayoutKind.Explicit

    I run understanding code in my bridge program to call the double dummy solver dds.dll.

    Code:
     <DllImport("dds.dll", CallingConvention:=CallingConvention.StdCall)> _
               Public Shared Function SolveBoard(ByVal deal As dealstruct, ByVal target As Integer, ByVal solutions As Integer, ByVal mode As Integer, ByRef tricks As futureTricks) As Integer
        End Function
    
        <StructLayout(LayoutKind.Explicit)> _
            Public Structure dealstruct
            <FieldOffset(0)> Public trump As Integer
            <FieldOffset(4)> Public first As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=3)> _
            <FieldOffset(8)> Public currentTrickSuit() As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=3)> _
            <FieldOffset(20)> Public currentTrickRank() As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=16)> _
            <FieldOffset(32)> Public remainCards(,) As Integer
    
        End Structure
        Public Structure futureTricks
    
            <FieldOffset(0)> Public nodes As Integer
    
            <FieldOffset(4)> Public cards As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=13)> _
            <FieldOffset(8)> Public suit() As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=13)> _
            <FieldOffset(12)> Public rank() As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=13)> _
            <FieldOffset(16)> Public Shadows equals() As Integer
            <MarshalAs(UnmanagedType.ByValArray, sizeconst:=13)> _
            <FieldOffset(20)> Public score() As Integer
        End Structure
        Public dealStr As New dealstruct
        Public futureStr As New futureTricks
        Public Sub Initialize()
            ReDim dealStr.currentTrickSuit(2)
            ReDim dealStr.currentTrickRank(2)
            ReDim dealStr.remainCards(3, 3)
            ReDim futureStr.suit(12)
            ReDim futureStr.rank(12)
            ReDim futureStr.equals(12)
            ReDim futureStr.score(12)
        End Sub
    After filling in the variables, the double dummy solver is called by:

    calldll = SolveBoard(deal Str, target, solutions, mode, futureStr)

    With a 32-bits machine this code is functioning correct, but with a 64-bit machine the code generates next error code:

    System.TypeLoad Exception:
    Could not load type 'Dealstruct' from assembly B-Bridge version 1.1.7, Culture=neutral , PublicKeyToken= null' because an object field at offset 20 that is incorrectly aligned or overlapped by a non-object field.

    Does anyone know which adjustments I have to make to the code so it will function correctly on 64-bit machine.
    Last edited by tlhintoq; Apr 7 '10, 03:59 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • CroCrew
    Recognized Expert Contributor
    • Jan 2008
    • 564

    #2
    TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Thanks,
    CroCrew~

    Comment

    Working...