Problem with RAS

  • Thread starter Thread starter CalvinRodo
  • Start date Start date
C

CalvinRodo

for some reason I continually get an invalid structure size when I call
RasDial. here is a little code snippet I would really appreciate it if
someone could give me a hand with this, I'm stumped.
Here is the structure that keeps giving me the error:

[StructLayoutAttribute(LayoutKind.Sequential,CharSet=CharSet.Auto)]
internal class RASDIALPARAMS
{
public int dwSize = 1060;// = Marshal.SizeOf(typeof(RASDIALPARAMS));

//The win32 api expects Fixed structure sizes so you need to
//specify the size using MarshalAs
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RAS_MaxEntryName +
1)]
public string szEntryName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)RAS_MaxPhoneNumber
+ 1)]
public string szPhoneNumber = null;
[MarshalAs(UnmanagedType.ByValTStr,
SizeConst=(int)RAS_MaxCallbackNumber + 1)]
public string szCallbackNumber = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)UNLEN + 1)]
public string szUserName = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)PWLEN + 1)]
public string szPassword = null;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=(int)DNLEN + 1)]
public string szDomain = null;
public int dwSubEntrym = 0;
public int dwCallbackId = 0;
};

These are my constants:
private const int RAS_MaxEntryName = 256;
private const int RAS_MaxPhoneNumber = 128;
private const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
private const int UNLEN = 256;
private const int PWLEN = 256;
private const int DNLEN = 15;

this is the declaration for my RasDial functino and the code segment
that is giving me the error

[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
private extern static uint RasDial(
[In]RASDIALEXTENSIONS lpRasDialExtensions,
[In]string lpszPhonebook,
[In]RASDIALPARAMS lpRasDialParams,
uint dwNotifierType,
Delegate lpvNotifier,
ref IntPtr lphRasConn
);

RasDialFunc dialFunc = new RasDialFunc(rdf);
if ((eCode = RasDial(null,null,rdp,0,dialFunc,ref hrasconn)) != 0)
{
//Throw an exception here or log an error whatever.
StringBuilder eString = new StringBuilder(255);
RasGetErrorString(eCode,eString,255);
System.Windows.Forms.MessageBox.Show ("Error: RasDial\n" + eString,
"Error");
}

Any email replies can be sent to calvin.rodo(at)service.canada.gc.ca
Calvin
 
Hi,

There are a couple of libraries that already implement RAS access in .net my
advise is to use one of these. try first opennetcf.org and codeproject I
found the one I'm using in one of those sites.
 
Back
Top