|
Posted by Chris De Herrera on September 28, 2007, 3:52 pm
Please log in for more thread options
Hi,
I understand you want some assistance, however this is a developer question.
I suggest that you post developer questions in
microsoft.public.pocketpc.developer.
--
Chris De Herrera
http://www.pocketpcfaq.com http://www.tabletpctalk.com http://www.pocketpctalk.com http://www.mobilitytalk.com
Windows Mobile Device Center FAQs -
http://www.pocketpcfaq.com/faqs/wmdc/index.htm ActiveSync Troubleshooting Guide -
http://www.pocketpcfaq.com/faqs/t-shootactivesync.htm
> i'm trying to make a list of RAS connections on a pocket pc 2003 device .
> and
> hear is my code. but it displaied only one connection on the combo box. it
> should be 11 connections. can any one check this one and explain to me
> whats
> wrong with this.
>
>
>
> using System;
>
> using System.Collections.Generic;
>
> using System.ComponentModel;
>
> using System.Data;
>
> using System.Drawing;
>
> using System.Text;
>
> using System.Windows.Forms;
>
>
>
>
>
> using System.Runtime.InteropServices;
>
> namespace Rastest
>
> {
>
>
> public partial class Form2 : Form
>
> {
>
>
> const int MAX_PATH = 260;
>
> const int RAS_MaxEntryName = 20;
>
> const int RAS_MaxDeviceType = 16;
>
> const int RAS_MaxPhoneNumber = 128;
>
> const int RAS_MaxDeviceName = 128;
>
>
>
> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
>
> struct RASCONN
>
> {
>
> public int dwSize;
>
> public IntPtr hrasconn;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
>
> public string szEntryName;
>
> }
>
> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
>
> struct RASCONNSTATUS
>
> {
>
> public int dwSize;
>
> public int rasconnstate;
>
> public int dwError;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceType + 1)]
>
> public string szDeviceType;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxDeviceName + 1)]
>
> public string szDeviceName;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxPhoneNumber + 1)]
>
> public string szPhoneNumber;
>
> }
>
>
> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
>
> struct RASENTRYNAME
>
> {
>
> public int dwSize;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = RAS_MaxEntryName + 1)]
>
> public string szEntryName;
>
> public int dwFlags;
>
> [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAX_PATH + 1)]
>
> public string szPhonebook;
>
> }
>
> [DllImport("coredll.dll", SetLastError = true)]//, CharSet =
> CharSet.Auto)]
>
> static extern uint RasEnumEntries(IntPtr reserved, IntPtr lpszPhonebook,
> [In, Out] RASENTRYNAME[] lprasentryname, ref int lpcb, ref int
> lpcEntries);
>
> [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
>
> static extern int RasEnumConnections([In, Out] RASCONN[] lprasconn,ref int
> lpcb,ref int lpcConnections);
>
> [DllImport("coredll.dll", SetLastError = true, CharSet = CharSet.Auto)]
>
> static extern int RasGetConnectStatus(IntPtr hrasconn,ref RASCONNSTATUS
> lprasconnstatus);
>
>
>
>
> /// <summary>
>
> /// </summary>
>
>
> public Form2()
>
> {
>
> InitializeComponent();
>
>
> int cb = Marshal.SizeOf(typeof(RASENTRYNAME)), entries = 0;
>
> RASENTRYNAME[] entryNames = new RASENTRYNAME[1];
>
> entryNames[0].dwSize = Marshal.SizeOf(typeof(RASENTRYNAME));
>
> //Get entry number
>
> uint nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb,
> ref
> entries);
>
> if (entries == 0) return;
>
> string[] _EntryNames = new string[entries];
>
> entryNames = new RASENTRYNAME[entries];
>
>
>
> nRet = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, entryNames, ref cb, ref
> entries);
>
>
>
>
> this.connname(entries);
>
>
>
>
> }
>
> public void Form2_Load(object sender, EventArgs e)
>
> {
>
>
> }
>
> public void connname(int entries)
>
> {
>
> int dwNumRasConnections = 0;
>
> RASCONN[] lpRasConnArray = new RASCONN[entries];
>
> lpRasConnArray.Initialize();
>
> lpRasConnArray[0].dwSize = Marshal.SizeOf(typeof(RASCONN));
>
> int dwRasConnArraySize = lpRasConnArray[0].dwSize * lpRasConnArray.Length;
>
> //dwNumRasConnections = 0;
>
> int nnRet = RasEnumConnections(lpRasConnArray, ref dwRasConnArraySize, ref
> dwNumRasConnections);
>
> // to the size of the structure to identify the version of the structure
> being passed
>
> lpRasConnArray[0].dwSize = Marshal.SizeOf(typeof(RASCONN));
>
> //enumerate all active RAS connections
>
> nnRet = RasEnumConnections(lpRasConnArray, ref dwRasConnArraySize, ref
> dwNumRasConnections);
>
> //return lpRasConnArray[dwNumRasConnections].szEntryName;
>
> for (int i = 0; i < entries; i++)
>
> {
>
>
> this.comboBox1.Items.Add(lpRasConnArray.szEntryName);
>
>
> }
>
> }
>
>
> }
>
> }
>
|