hello, all.
I am trying to convert a struct from VB to c# in order to use an old DLL.
Here is the definition in VB
Public Type CHost
Host As String * 60
Port As String * 5
Info As String * 120 'Inof returned from host
Timeout As String * 10
End Type
In the sample VB code:
Public Declare Function CConnect Lib "OLDDLL.DLL" (Host As CHost) As Integer
iError = CConnect(TheHost)
and then the CHost.Info was set by the remote host.
I converted it to(C#)
public struct CHost
{
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=60)]
public string Host; //host name
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=5)]
public string Port; //host port
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=120)]
public string Info; //Info returned from remote host
[System.Runtime.InteropServices.MarshalAs(System.Ru ntime.InteropServices.Unm
anagedType.ByValTStr,SizeConst=5)]
public string Timeout; //timeout
};
in my c# code.
[DllImport("OLDDLL",EntryPoint="CConnect")]
public static extern short CConnect(ref CHost Host);
short ierror = CConnect(ref theHost);
I can connect to the remote host but the theHost.Info was not set.
Could anybody let me know what I was doing wrong and what is the right way
to do it?