/// <summary> /// cRASDisplay /// </summary> public cRASDisplay() { m_connected = true; cRAS lpras = new cRAS(); RASCONN lprasConn = new RASCONN(); lprasConn.dwSize = Marshal.SizeOf(typeof(RASCONN)); lprasConn.hrasconn = IntPtr.Zero; int lpcb = 0; int lpcConnections = 0; int nRet = 0; lpcb = Marshal.SizeOf(typeof(RASCONN)); nRet = cRAS.RasEnumConnections(ref lprasConn, ref lpcb, ref lpcConnections); if (nRet != 0) { m_connected = false; return; } if (lpcConnections > 0) { RasStats stats = new RasStats(); m_ConnectedRasHandle = lprasConn.hrasconn; cRAS.RasGetConnectionStatistics(lprasConn.hrasconn, stats); m_ConnectionName = lprasConn.szEntryName; m_ConnectDuration = stats.dwConnectDuration; int Hours = 0; int Minutes = 0; int Seconds = 0; Hours = ((stats.dwConnectDuration / 1000) / 3600); Minutes = ((stats.dwConnectDuration / 1000) / 60) - (Hours * 60); Seconds = ((stats.dwConnectDuration / 1000)) - (Minutes * 60) - (Hours * 3600); m_duration = Hours + " 小时 " + Minutes + " 分钟 " + Seconds + " 秒"; m_TX = stats.dwBytesXmited; m_RX = stats.dwBytesRcved; //获取IP RASPPPIP structProjection = new RASPPPIP(); uint uiProjSize = (uint)structProjection.dwSize; try { uint errorCode = cRAS.RasGetProjectionInfo(m_ConnectedRasHandle, RASPROJECTION.RASP_PppIp, structProjection, ref uiProjSize); } catch { } m_ip = structProjection.szIpAddress; } else { m_connected = false; } int lpNames = 1; int entryNameSize = 0; int lpSize = 0; RasEntryName[] names = null; entryNameSize = Marshal.SizeOf(typeof(RasEntryName)); lpSize = lpNames * entryNameSize; names = new RasEntryName[lpNames]; names[0].dwSize = entryNameSize; uint retval = cRAS.RasEnumEntries(null, null, names, ref lpSize, out lpNames); //if we have more than one connection, we need to do it again if (lpNames > 1) { names = new RasEntryName[lpNames]; for (int i = 0; i < names.Length; i++) { names[i].dwSize = entryNameSize; } retval = cRAS.RasEnumEntries(null, null, names, ref lpSize, out lpNames); } m_ConnectionNames = new string[names.Length]; if (lpNames > 0) { for (int i = 0; i < names.Length; i++) { m_ConnectionNames[i] = names[i].szEntryName; } } }
internal static extern int RasEnumConnections ( ref RASCONN lprasconn, // buffer to receive connections data ref int lpcb, // size in bytes of buffer ref int lpcConnections // number of connections written to buffer );