none
c# Win CE 6 Ras Dial-up Connection RRS feed

  • Question

  • I received the following article reference . But I could not solve the following errors .(What namespace Utils?) Please can you help ?

    Dialing RAS from WinCE device

    using System;
    using System.Windows.Forms;
    using System.Text;
    using OpenNETCF.Net;
    
    namespace SmartDeviceProject2
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (Utils.ReadRegString(Utils.HKEY_CURRENT_USER, @"Comm\RasBook\GPRS", "DevCfg"))
                {
                   textBoxSysVers.Text="Succeeded Make Text File.";
                }
            }
    
            public static bool ReadRegString(IntPtr hKey, string lpszSubKey, string lpValueName)
            {
                try
                {
                    string str = "";
                    byte[] lpData = new byte[684];
                    uint lpcbValue = 684;
                    uint dwType = Utils.REG_BINARY;
                    IntPtr phkResult = new IntPtr();
                    Utils.RegOpenKeyEx(hKey, lpszSubKey, 0, 0, ref phkResult);
                    if (phkResult != IntPtr.Zero)
                    {
                        int x = Utils.RegQueryValueEx(phkResult, lpValueName, 0, ref dwType, lpData, ref lpcbValue);
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < 684; i++)
                        {
                            if (i != 683)
                                sb.Append(lpData[i].ToString() + "|");
                            else
                                sb.Append(lpData[i].ToString());
                        }
                        using (System.IO.StreamWriter outfile = new System.IO.StreamWriter("\\Temp\\"))
                        {
                            outfile.Write(sb.ToString());
                        }
                        Utils.RegCloseKey(phkResult);
                    }
                }
    
                catch (Exception)
                {
                    throw;
                }
            }
    
    
            public static Boolean WriteRegValue(IntPtr hKey, string lpszSubKey, string lpValueName1, string lpValueName1,uint dwType)
            {
                int iOper = 1;
                filePath = @"`enter code here`\DevCfg.txt";
                IntPtr phkResult = new IntPtr();
                Utils.RegOpenKeyEx(hKey, lpszSubKey, 0, 0, ref phkResult);
                if (phkResult == IntPtr.Zero)
                {
                    int iSecurity = 0;
                    int dwDisp = 0;
                    RegCreateKeyEx(hKey, lpszSubKey, 0, null, 0, 0, ref iSecurity, ref phkResult, ref dwDisp);
                }
                if (phkResult != IntPtr.Zero)
                {
                    byte[] bytes = new byte[684];
                    string[] text = new string[684];
                    using (System.IO.StreamReader streamReader = new System.IO.StreamReader(filePath, Encoding.UTF8))
                    {
                        text = streamReader.ReadToEnd().Split('|');
                    }
                    for (int i = 0; i < 684; i++)
                    {
                        bytes[i] = Convert.ToByte(Convert.ToInt32(text[i]));
                    }
                    iOper = Utils.RegSetValueEx(phkResult, lpValueName1, 0, dwType, bytes, (uint)bytes.Length);
                    Utils.RegCloseKey(phkResult);
                }   
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                private const string CONNAME = "GPRS";
                private const string PHONENR = "*99#";
                private const string USER = "xx";
                private const string PWD = "xx";
                private const string DEVICE_TYPE = "modem";
                private const string DEVICE_NAME = "Cellular Line";
    
                 RasEntry cEntry = new RasEntry()
                {
                    Name = CONNAME,
                    CountryCode = 91,
                    AreaCode = "120",
                    PhoneNumber = PHONENR,
                    DeviceName = DEVICE_NAME,
                    DeviceType = DEVICE_TYPE,
                    IPAddress = "0.0.0.0",
                    IPAddressDns = "0.0.0.0",Options=4194304
                };
    
                RasDialParams dialParams = new RasDialParams()
                {
                    UserName = USER,
                    Password = PWD,
                    EntryName = CONNAME,
                    Domain = " "
                };
    
                if (Utils.WriteRegValue(Utils.HKEY_CURRENT_USER, @"Comm\RasBook\GPRS", "DevCfg","Entry",3))
                {
                    RasError re = cEntry.Dial(false, new RasDialParams(CONNAME, USER, PWD));
    
                    RasError rs = re;
                    textBoxInfo.Text = re.ToString() + " : Dial Status";
                    if(rs.ToString()=="Success")
                    textBoxInfo.Text = cEntry.Status.State.ToString() + " : Dial Status";
                }
            }
        }
    }

    Errors :

    • The parameter name 'lpValueName1' is a duplicate
    • The name 'filePath' does not exist in the current context
    • The name 'Utils' does not exist in the current context
    • The name 'RegCreateKeyEx' does not exist in the current context
    • The name 'filePath' does not exist in the current context

    Sunday, June 28, 2015 9:36 AM

All replies

  • In the original article on Stack Overflow, the answer includes calls to some library called "Utils" which you are also trying to use.  Utils is not part of the Compact Framework and it's not part of the OpenNETCF RAS library either.  It must be something the answerer either wrote of found and without it, the code as written cannot compile.

    On the plus side, it looks like it's only used for making registry modifications.  I'm guessing this is code from back in the CF 1.0 days when there were no registry access APIs already in the CF.  What you're going to need to do is delete the ReadRegString and WriteRegValue methods completely and then replace all of the remaining "Utils" calls with appropriate Microsoft.Win32.Registry calls.  On the plus side, using the API that's present in the CF will greatly simplify your code.

    Wednesday, July 1, 2015 1:00 PM