I'm having trouble when I ported this Interop Code from VB6 to C#
VB6:
Type Dpi_t
dpiDrSuPsd(DPI_PRG_LEN) As Byte
dpiMyPort As Long
dpiHostAdr(DPI_MAX_HOST) As Byte
dpiHostCnt As Integer
dpiVoidCom As Long
dpiRspBdy As Long
dpiCmData As Long
dpiRdcxData As Long
dpiLstErr As Long
dpiONoUa As Byte
dpiOTooMuch As Byte
dpiOBar As Byte
dpiVPin As Byte
DpiPin As Long
dpiCda(DPI_CDA_LEN) As Byte
dpiEcCyc(DPI_CYC_LEN) As Byte
dpitemp(6000) As Byte
End Type
C#
[StructLayout(LayoutKind.Sequential)]
public struct Dpi_t
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DPI_PRG_LEN)]
public byte[] dpiDrSuPsd;
public long dpiMyPort;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DPI_MAX_HOST)]
public byte[] dpiHostAdr;
public int dpiHostCnt;
public long dpiVoidCom;
public long dpiRspBdy;
public long dpiCmData;
public long dpiRdcxData;
public long dpiLstErr;
public byte dpiONoUa;
public byte dpiOTooMuch;
public byte dpiOBar;
public byte dpiVPin;
public long DpiPin;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DPI_CDA_LEN)]
public byte[] dpiCda;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = DPI_CYC_LEN)]
public byte[] dpiEcCyc;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6000)]
public byte[] dpitemp;
}
I can't get them to match, and I just ran out of ideas. What do you guys think?
I've never done VB6 to C# interop. But I think you are using the wrong C# data types in your .Net structure.
According to this summary of Visual Basic 6.0 data types a
Integer
is 2 Bytes in size and aLong
is 4 Bytes in size.So for a VB6
Integer
you should use theshort
(Int16
) data type and forLong
you should use theint
(Int32
) data type.Hope, this helps.