Incorrect Structure Size of RasConnStatus

  • Thread starter Thread starter Dennis Sia via DotNetMonster.com
  • Start date Start date
D

Dennis Sia via DotNetMonster.com

Hi everybody,
Unable to resolve the size of RasConnStatus which causing the
RasGetConnectStatus() of code # 632. Is there anyone who can tell me how to
get the correct size (structure) for the RasConstatus? Thanks in Advanced.

RasGetConnectStatus returning 632 error code.

Code:
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
internal class RASCONNSTATUS
{
public int dwSize = 0;
public RASCONNSTATE  rasconnstate;
public int dwError = 0;
[MarshalAs(UnmanagedType.ByValTStr,SizeConst=(int)RasFieldSizeConstants.
RAS_MaxDeviceType+1)]
public string szDeviceType = null;
public string szDeviceName = null;
}

dennis
 
Dennis said:
Hi everybody,
Unable to resolve the size of RasConnStatus which causing the
RasGetConnectStatus() of code # 632. Is there anyone who can tell me how to
get the correct size (structure) for the RasConstatus? Thanks in Advanced.
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
internal class RASCONNSTATUS

Try
Marshal.SizeOf(typeof(RASCONNSTATUS))

Till
 
Thanks for replying, Till

Still causing a result of 632 even the connection is created.

Code:
private void btnRasConnect_Click(object sender, System.EventArgs e)
{
.. ..  ..
if (this.CheckRasConnection(this.IDConnexionRAS) == false)
this.OpeningConnection();
... ....
}

private void OpeningConnection()
{
this.IDConnexionRAS = 0;
string connectName = this.txtIpAddress.Text;
string user = this.txtUsername.Text;
string pass = this.txtPassword.Text;

this.OpenConnection(connectName,user,pass,"");
}

public bool OpenConnection(string pNomConnection,string pUser,string
pPassword,string pDomain)
{
int i;
int j;

#region [ RASDIALPARAMS ]
// The size of the table of bytes representing structure RASDIALPARAMS is of
1464 bytes
TabParams = new byte[1464];
BitConverter.GetBytes(1464).CopyTo(TabParams,0);
i = 4;
j = i;
foreach (char Carac in pNomConnection)
{
BitConverter.GetBytes(Carac).CopyTo(TabParams, j);
j += 2;
}
i += (42 + 258 + 98);

j = i;
foreach (char Carac in pUser)
{
BitConverter.GetBytes(Carac).CopyTo(TabParams, j);
j += 2;
}
i += 514;
j = i;
foreach (char Carac in pPassword)
{
BitConverter.GetBytes(Carac).CopyTo(TabParams, j);
j += 2;
}
i += 514;

#endregion

uint res = RasDial(0,null,TabParams,0,0,ref IDConnexionRAS);

if (res == 0)
{
this.connectStatus = true;
if (this.IDConnexionRAS > 0)
this.IDDisconnectRAS = this.IDConnexionRAS;

status.rasconnstate = RASCONNSTATE.RASCS_Connected;
RasAPI.RasConnectionNotification(IDConnexionRAS,this._DisconnEvent.
Handle
,(int)RASNOTIFICATION.RASCN_Connection);
Console.WriteLine ("RAS TRUE");
this.lblConStat.Text = "Connected";

return true;
}
. .. .
}

public bool GetRasConnectStatus(int idConn)
{
status = new RASCONNSTATUS();
status.dwSize = Marshal.SizeOf(typeof(RASCONNSTATUS));
//uint res = 1;
res = RasAPI.RasGetConnectStatus(idConn, ref status);

if (res == 0 && status.rasconnstate == RASCONNSTATE.RASCS_Connected)
{
this.IsRasConnected = true;
return true;
}
else
{
this.IsRasConnected = false;
return false;
}
}

What is wrong? Something missing?

dennis

Till said:
Hi everybody,
Unable to resolve the size of RasConnStatus which causing the
RasGetConnectStatus() of code # 632. Is there anyone who can tell me how to
get the correct size (structure) for the RasConstatus? Thanks in Advanced.
[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Auto)]
internal class RASCONNSTATUS

Try
Marshal.SizeOf(typeof(RASCONNSTATUS))

Till
 
Back
Top