RAS

M

Marc Dolata

Hi ng,

I'm trying to implement RAS-functionality within my application.
Establishing a connection is no problem (so far). But when I try to
disconnect (using RasHangUp), the connection won't be dropped.
here are my declarations and function-calls:


public const int RAS_MaxPhoneNumber = 128;
public const int RAS_MaxEntryName = 256;
public const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
public const int UNLEN = 256;
public const int PWLEN = 256;
public const int DNLEN = 15;

public delegate void Callback(uint unMsg, int rasconnstate, int dwError)

[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)]
public struct RASDIALPARAMS
{
public int dwSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxEntryName + 1)]
public string szEntryName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxCallbackNumber+ 1)]
public string szCallbackNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=UNLEN + 1)]
public string szUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=PWLEN + 1)]
public string szPassword;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=DNLEN + 1)]
public string szDomain;
public int dwSubEntry;
public int dwCallbackId;
}
[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasHangUp(
ref int hrasconn
);
[DllImport("rasapi32.dll", CharSet=CharSet.Auto)]
public extern static int RasDial (
int lpRasDialExtensions,
string lpszPhonebook,
ref RASDIALPARAMS lprasdialparams,
int dwNotifierType,
Callback lpvNotifier,
ref int lphRasConn
);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static void Sleep (
int dwMilliSeconds
);

private RASDIALPARAMS rasDialParams;
private int connection;
private Callback notifier;

public RasManager(Callback notifier)
{
this.notifier = notifier;
connection = 0;
rasDialParams = new RASDIALPARAMS();
rasDialParams.dwSize = Marshal.SizeOf(rasDialParams);
}

public int Connect()
{
Callback rasDialFunc = this.notifier;
rasDialParams.szEntryName += "\0";
rasDialParams.szUserName += "\0";
rasDialParams.szPassword += "\0";
int result = RasDial (0, null, ref rasDialParams, 0, rasDialFunc, ref
connection);
return result;
}
public void Disconnect()
{
RasHangUp(ref connection);
Sleep(3000);
}

The Connect-method will successfully connect with a defined phonebook-entry.
When I try to disconnect, RasHangUp returns 668 (=connection dropped). But
the connection remains up.
I tested if I got a handler != 0 (in connection) - that's ok so far.. maybe
there is something wrong with declaration of "connection" / "lphRasConn"
that I don't know?

Any ideas what's going wrong here?

TIA,
Marc
 
F

Floyd Burger

why reinvent the wheel? There are several RAS component freely available.
I use the one in ElementsEx from www.componentscience.net.

--
floyd
Marc Dolata said:
Hi ng,

I'm trying to implement RAS-functionality within my application.
Establishing a connection is no problem (so far). But when I try to
disconnect (using RasHangUp), the connection won't be dropped.
here are my declarations and function-calls:


public const int RAS_MaxPhoneNumber = 128;
public const int RAS_MaxEntryName = 256;
public const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber;
public const int UNLEN = 256;
public const int PWLEN = 256;
public const int DNLEN = 15;

public delegate void Callback(uint unMsg, int rasconnstate, int dwError)

[StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)]
public struct RASDIALPARAMS
{
public int dwSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxEntryName + 1)]
public string szEntryName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxCallbackNumber+ 1)]
public string szCallbackNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=UNLEN + 1)]
public string szUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=PWLEN + 1)]
public string szPassword;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=DNLEN + 1)]
public string szDomain;
public int dwSubEntry;
public int dwCallbackId;
}
[DllImport("rasapi32.dll",CharSet=CharSet.Auto)]
public extern static uint RasHangUp(
ref int hrasconn
);
[DllImport("rasapi32.dll", CharSet=CharSet.Auto)]
public extern static int RasDial (
int lpRasDialExtensions,
string lpszPhonebook,
ref RASDIALPARAMS lprasdialparams,
int dwNotifierType,
Callback lpvNotifier,
ref int lphRasConn
);
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static void Sleep (
int dwMilliSeconds
);

private RASDIALPARAMS rasDialParams;
private int connection;
private Callback notifier;

public RasManager(Callback notifier)
{
this.notifier = notifier;
connection = 0;
rasDialParams = new RASDIALPARAMS();
rasDialParams.dwSize = Marshal.SizeOf(rasDialParams);
}

public int Connect()
{
Callback rasDialFunc = this.notifier;
rasDialParams.szEntryName += "\0";
rasDialParams.szUserName += "\0";
rasDialParams.szPassword += "\0";
int result = RasDial (0, null, ref rasDialParams, 0, rasDialFunc, ref
connection);
return result;
}
public void Disconnect()
{
RasHangUp(ref connection);
Sleep(3000);
}

The Connect-method will successfully connect with a defined
phonebook-entry. When I try to disconnect, RasHangUp returns 668
(=connection dropped). But the connection remains up.
I tested if I got a handler != 0 (in connection) - that's ok so far..
maybe there is something wrong with declaration of "connection" /
"lphRasConn" that I don't know?

Any ideas what's going wrong here?

TIA,
Marc
 
M

marc

I searched a while for such a component but couldn't find any (I think
I have to reinvent my web-search :) ) I've tested everything I need,
works good for me.
however, thank you very much.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top