Hello,
i am new to C# and i am having trouble to use the RasconnectionNotification call.
This is how far i managed to get. The problem is that i don't really know how to get to run. i did managed to get it to run in VB 6 via WaitForMultipleObjects but threading is so confusing in C#
using System;
using System.Runtime.InteropServices;
namespace Detect_Connection
{
public class Detect
{
const long RASCN_Connection = 0x00000001;
const long RASCN_Disconnection = 0x00000002;
public struct SECURITY_ATTRIBUTES{
public long nLength;
public long IpSecurityDescriptor;
public long bInheritHandle;
public SECURITY_ATTRIBUTES(long nLength,long IpSecurityDescriptor,long bInheritHandle){
this.nLength = nLength;
this.bInheritHandle = bInheritHandle;
this.IpSecurityDescriptor = IpSecurityDescriptor;
}
}
[DllImport("rasapi32.dll")]
public static extern int RasConnectionNotification(long hRasConn,long hEvents,long dwFlags);
[DllImport("kernel32.dll")]
public static extern long CreateEvent
(SECURITY_ATTRIBUTES lpEventAttributes,bool bManualReset,bool bInitialState,string lpName);
public long MonitorConnection(){
long[] hEvents = {0,1};
long RasNotif,hRasConn = 0;
long WaitRet;
SECURITY_ATTRIBUTES Sd = new SECURITY_ATTRIBUTES();
Sd.nLength = Marshal.SizeOf(Sd);
Sd.bInheritHandle = 0;
Sd.IpSecurityDescriptor = 0;
hEvents[0] = CreateEvent(Sd, true, false, "RASStatusNotificationObject1");
hEvents[1] = CreateEvent(Sd, true, false, "RASStatusNotificationObject2");
RasNotif = RasConnectionNotification(hRasConn,hEvents[0],RASCN_Connection);
RasNotif = RasConnectionNotification(hRasConn,hEvents[1],RASCN_Disconnection);
WaitRet = RasNotif;
return WaitRet;
}
}
}
i am new to C# and i am having trouble to use the RasconnectionNotification call.
This is how far i managed to get. The problem is that i don't really know how to get to run. i did managed to get it to run in VB 6 via WaitForMultipleObjects but threading is so confusing in C#
using System;
using System.Runtime.InteropServices;
namespace Detect_Connection
{
public class Detect
{
const long RASCN_Connection = 0x00000001;
const long RASCN_Disconnection = 0x00000002;
public struct SECURITY_ATTRIBUTES{
public long nLength;
public long IpSecurityDescriptor;
public long bInheritHandle;
public SECURITY_ATTRIBUTES(long nLength,long IpSecurityDescriptor,long bInheritHandle){
this.nLength = nLength;
this.bInheritHandle = bInheritHandle;
this.IpSecurityDescriptor = IpSecurityDescriptor;
}
}
[DllImport("rasapi32.dll")]
public static extern int RasConnectionNotification(long hRasConn,long hEvents,long dwFlags);
[DllImport("kernel32.dll")]
public static extern long CreateEvent
(SECURITY_ATTRIBUTES lpEventAttributes,bool bManualReset,bool bInitialState,string lpName);
public long MonitorConnection(){
long[] hEvents = {0,1};
long RasNotif,hRasConn = 0;
long WaitRet;
SECURITY_ATTRIBUTES Sd = new SECURITY_ATTRIBUTES();
Sd.nLength = Marshal.SizeOf(Sd);
Sd.bInheritHandle = 0;
Sd.IpSecurityDescriptor = 0;
hEvents[0] = CreateEvent(Sd, true, false, "RASStatusNotificationObject1");
hEvents[1] = CreateEvent(Sd, true, false, "RASStatusNotificationObject2");
RasNotif = RasConnectionNotification(hRasConn,hEvents[0],RASCN_Connection);
RasNotif = RasConnectionNotification(hRasConn,hEvents[1],RASCN_Disconnection);
WaitRet = RasNotif;
return WaitRet;
}
}
}