For some reasons whenever I call RasGetConnectStatus I always get error code 632: "An Incorrect Structure Size was Detected" I even went so far as to call the function over and over again starting with a size of zero and incrementing it to see if I could find the right size, I always got the same error.
so here are the constants I'm using:
private const int RAS_MaxPhoneNumber = 128;
private const int RAS_MaxDeviceName = 128;
private const int RAS_MaxDeviceType = 16;
Here is the definition of the structure:
[StructLayoutAttribute(LayoutKind.Sequential,Pack=4,CharSet=CharSet.Auto)]
internal class RASCONNSTATUS
{
public int dwSize = Marshal.SizeOf(typeof(RASCONNSTATUS));
public RASCONNSTATErasconnstate;
public int dwError = 0;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RAS_MaxDeviceType + 1)]
public string szDeviceType = null ;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int RAS_MaxDeviceName + 1)]
public string szDeviceName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber = null;
};
I've tried with out the phonenumber member and have gotten the same problem.
Here is the definition for RasGetConnectStatus
[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
private extern static uint RasGetConnectStatus(
IntPtr hrasconn,
ref RASCONNSTATUS lprasconnstatus
);
And finally the code where i call the function:
internal RASCONNSTATE getConnectionStatus()
{
RASCONNSTATUS rcs = new RAS.RASCONNSTATUS();
System.Windows.Forms.MessageBox.Show("Size: " + Marshal.SizeOf(rcs) ,"Test");
if (hrasconn != (IntPtr)null)
{
uint eCode;
if ((eCode = RasGetConnectStatus(hrasconn,ref rcs)) != 0)
{
//Throw an exception if there is an error
StringBuilder eString = new StringBuilder(255);
RasGetErrorString(eCode,eString,255);
throw new RASGetConnStatException(eString.ToString());
}
return rcs.rasconnstate;
}else
//I added this to the enumeration Rasconnstate
return RASCONNSTATE.RASCS_Null;
}
I have been banging my head against the keyboard trying to figure out my problem for the past couple of days someone please help me figure out what i'm doing wrong. I just can't see it.
-Calvin Rodo

Problem with RasGetConnectStatus.
Puffychan
this is the proper syntax
[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
private extern static uint RasGetConnectStatus(
[In]IntPtr hrasconn,
[in,Out]RASCONNSTATUS lprasconnstatus
);