'RAS'에 해당되는 글 1건

  1. 2006/09/18 hancem WINCE/PPC RAS 연결 C#소스

개발장비: BIP-5000  WINCE 5.0
개발툴:  VS.NET 2005 C#

WINCE에서는 Connection Manager를 사용하지 못합니다.  
cellcore.dll  파일이 WINCE 이미지에 없습니다.
WINCE에서 CDMA 연동 하기 위해서는 RAS 를 사용하셔야 합니다.
RAS를 사용하기 위해  rasapi32.dll 를 찾으시는 분이 있는데,
WINCE에는 coredll.dll  해당 api 가 포함되어 있습니다.
인터넷 써핑중 초간단 소스가 있어서 올려드립니다.

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 DeviceApplication7 {
   public partial class Form1 : Form {
       public Form1() {
           InitializeComponent();
       }

      private IntPtr RasConn = IntPtr.Zero;        
       private void button1_Click(object sender, EventArgs e) {
           try {
               IntPtr tmpRasConn;
               Cursor.Current = Cursors.WaitCursor;

               // 설정은 PDA마다 틀릴 수 있습니다.
               // EntryName: 인터넷연결
               // 사용자: sktelecom
               //  PWD : SKT 없음
               uint nErr = myRasDial("인터넷연결", "sktelecom", "", out tmpRasConn);
               if (nErr == 0) RasConn = tmpRasConn;

               // 테스트
               MessageBox.Show(string.Format("{0}:{1}", nErr, tmpRasConn));
           }
           catch (Exception er) {
               MessageBox.Show(er.Message);
           }
           finally {
               Cursor.Current = Cursors.Default;
           }
       }

       private void button2_Click(object sender, EventArgs e) {
           if (RasConn == IntPtr.Zero) return;
           Cursor.Current = Cursors.WaitCursor;
           uint nErr = RasHangUp(RasConn);
           RasConn = IntPtr.Zero;
           MessageBox.Show(nErr.ToString());
           Cursor.Current = Cursors.Default;
       }

       // WINCE 5.0, VS.NET 2005 C# =============================================
       // 출처: http://www.codecomments.com/archive425-2006-2-797845.html
       // Connecting to GPRS programmatically in C# (RAS,RasDial)
       // Author: Aleks S.   2006-02-08, 10:28 am
       // 주의사항: 빌드옵션에서 '안전하지 않은 코드 허용' 체크 하세요.!!
       //========================================================================
       unsafe public static uint myRasDial(string EntryName, string UserName,
           string Password, out IntPtr RasConn) {
           uint r = 0;
           RasConn = IntPtr.Zero;
           byte[] bRASDIALPARAMS = new byte[1464];
           fixed (byte* pAddr = bRASDIALPARAMS) {
               byte* pCurrent = pAddr;
               Marshal.WriteInt32((IntPtr)pCurrent, bRASDIALPARAMS.Length);
               pCurrent += 4;
               foreach (byte b in Encoding.Unicode.GetBytes(EntryName)) {
                   Marshal.WriteByte((IntPtr)pCurrent, b);
                   pCurrent++;
               }

               pCurrent = pAddr + 0x192;//0x192 - offset for RASDIALPARAMS.UserName
               foreach (byte b in Encoding.Unicode.GetBytes(UserName)) {
                   Marshal.WriteByte((IntPtr)pCurrent, b);
                   pCurrent++;
               }


               pCurrent = pAddr + 0x394;//0x394 - offset for RASDIALPARAMS.Password
               foreach (byte b in Encoding.Unicode.GetBytes(Password)) {
                   Marshal.WriteByte((IntPtr)pCurrent, b);
                   pCurrent++;
               }

               r = RasDial(IntPtr.Zero, IntPtr.Zero, (IntPtr)pAddr, 0, IntPtr.Zero, ref RasConn);
           }
           return r;
       }

       [DllImport("coredll.dll")]
       public static extern uint RasDial(IntPtr dialExtensions, IntPtr phoneBookPath,
           IntPtr rasDialParam, uint NotifierType,IntPtr notifier, ref IntPtr pRasConn);

       [DllImport("coredll.dll")]
       public static extern uint RasHangUp(IntPtr pRasConn);        
   }
}

2006/09/18 17:22 2006/09/18 17:22
TAG , ,