看看楼上白兄台的帖子,讲的一个API InternetAutoDial,我在微软的新闻组里也找到一个不同的思路,所以也贴了过来. 原作出处: news://news.microsoft.com, 在Csharp英文组,用关键字 RAS 可以找到. 由于没有猫,这个代码没有测试. --------------------------------------------- Hi Daniel,I'm not sure how to detect connections, but here is an example for calling RAS APIs from C#. Hope it can bring you some ideas:/*************************************************************************** * using System; using System.Runtime.InteropServices;namespace RAS { public class RasManager { public const int RAS_MaxEntryName = 256; public const int RAS_MaxPhoneNumber = 128; public const int UNLEN = 256; public const int PWLEN = 256; public const int DNLEN = 15; public const int MAX_PATH = 260; public const int RAS_MaxDeviceType = 16; public const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber; public delegate void Callback(uint unMsg, int rasconnstate, int dwError); [StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)] public struct RASDIALPARAMS { public int dwSize; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxEntryName + 1)] public string szEntryName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxPhoneNumber + 1)] public string szPhoneNumber; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxCallbackNumber+ 1)] public string szCallbackNumber; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=UNLEN + 1)] public string szUserName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=PWLEN + 1)] public string szPassword; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=DNLEN + 1)] public string szDomain; public int dwSubEntry; public int dwCallbackId; } [DllImport("rasapi32.dll", CharSet=CharSet.Auto)] public static extern int RasDial (int lpRasDialExtensions, string lpszPhonebook, ref RASDIALPARAMS lprasdialparams, int dwNotifierType, Callback lpvNotifier, ref int lphRasConn); private RASDIALPARAMS RasDialParams; private int Connection; public RasManager() { Connection = 0; RasDialParams = new RASDIALPARAMS(); RasDialParams.dwSize = Marshal.SizeOf(RasDialParams); } #region Properties public string UserName { get { return RasDialParams.szUserName; } set { RasDialParams.szUserName = value; } } public string Password { get { return RasDialParams.szPassword; } set { RasDialParams.szPassword = value; } } public string EntryName { get { return RasDialParams.szEntryName; } set { RasDialParams.szEntryName = value; } } #endregion public int Connect() { Callback rasDialFunc = new Callback(RasManager.RasDialFunc); RasDialParams.szEntryName += "\0"; RasDialParams.szUserName += "\0"; RasDialParams.szPassword += "\0"; int result = RasDial (0, null, ref RasDialParams, 0, rasDialFunc, ref Connection); return result; } public static void RasDialFunc(uint unMsg, int rasconnstate, int dwError) { } } }An example of establishing a connection:RasManager myRas = new RasManager(); myRas.EntryName = "MyPhonebook entry"; // entry name in phonebook myRas.UserName = "username"; myRas.Password = "password"; myRas.Connect().ToString();/*************************************************************************** *******Regards,Felix Wu ============= This posting is provided "AS IS" with no warranties, and confers no rights. -------------------- >From: "Daniel Weber" <[email protected]> >Newsgroups: microsoft.public.dotnet.languages.csharp >Subject: Ras API >Date: Sat, 17 Aug 2002 14:29:32 +0200 >Organization: T-Online >Lines: 8 >Message-ID: <[email protected]> >Mime-Version: 1.0 >Content-Type: text/plain; charset=ISO-8859-1 >Content-Transfer-Encoding: 8bit >X-Trace: news.t-online.com 1029587368 02 26601 calPbRfGScAO0w 020817 12:29:28 >X-Complaints-To: [email protected] >X-Sender: [email protected] >X-Priority: 3 >X-MSMail-Priority: Normal >X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 >Path: cpmsftngxa06!tkmsftngp01!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.co m!t-online.de!news.t-online.com!not-for-mail >Xref: cpmsftngxa06 microsoft.public.dotnet.languages.csharp:86230 >X-Tomcat-NG: microsoft.public.dotnet.languages.csharp > >Can somebody provide some working code to access the ras api and detect >connections? >Thank you > >Daniel > > > >
mscomm是一个串口通讯的控件,不知道如何能用来拨号? 有人用过这个吗?■■■■■ To teach a fish how to swim. ■■■■■
如果是内置猫呢?■■■■■ To teach a fish how to swim. ■■■■■
TheAres(班门斧)的方法不错,可以拨号,我前几天也搜到了这短代码,不过分还是要送
为什么TheAres(班门斧)的这代码在98下会出现610错误?
http://expert.csdn.net/Expert/topic/1713/1713862.xml?temp=.3772241另外你也可以试试这个可以否? [DllImport("wininet.dll")] public static extern bool InternetAutoDial( [MarshalAs(UnmanagedType.U4) int dwFlags, IntPtr hwndParent);
原作出处: news://news.microsoft.com, 在Csharp英文组,用关键字 RAS 可以找到.
由于没有猫,这个代码没有测试.
---------------------------------------------
Hi Daniel,I'm not sure how to detect connections, but here is an example for calling
RAS APIs from C#. Hope it can bring you some ideas:/***************************************************************************
*
using System;
using System.Runtime.InteropServices;namespace RAS
{
public class RasManager
{
public const int RAS_MaxEntryName = 256;
public const int RAS_MaxPhoneNumber = 128;
public const int UNLEN = 256;
public const int PWLEN = 256;
public const int DNLEN = 15;
public const int MAX_PATH = 260;
public const int RAS_MaxDeviceType = 16;
public const int RAS_MaxCallbackNumber = RAS_MaxPhoneNumber; public delegate void Callback(uint unMsg, int rasconnstate, int dwError); [StructLayout(LayoutKind.Sequential, Pack=4, CharSet=CharSet.Auto)]
public struct RASDIALPARAMS
{
public int dwSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxEntryName + 1)]
public string szEntryName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxPhoneNumber + 1)]
public string szPhoneNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=RAS_MaxCallbackNumber+ 1)]
public string szCallbackNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=UNLEN + 1)]
public string szUserName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=PWLEN + 1)]
public string szPassword;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=DNLEN + 1)]
public string szDomain;
public int dwSubEntry;
public int dwCallbackId;
} [DllImport("rasapi32.dll", CharSet=CharSet.Auto)]
public static extern int RasDial (int lpRasDialExtensions, string
lpszPhonebook,
ref RASDIALPARAMS lprasdialparams, int dwNotifierType,
Callback lpvNotifier, ref int lphRasConn); private RASDIALPARAMS RasDialParams;
private int Connection; public RasManager()
{
Connection = 0;
RasDialParams = new RASDIALPARAMS();
RasDialParams.dwSize = Marshal.SizeOf(RasDialParams);
} #region Properties
public string UserName
{
get
{
return RasDialParams.szUserName;
}
set
{
RasDialParams.szUserName = value;
}
} public string Password
{
get
{
return RasDialParams.szPassword;
}
set
{
RasDialParams.szPassword = value;
}
} public string EntryName
{
get
{
return RasDialParams.szEntryName;
}
set
{
RasDialParams.szEntryName = value;
}
}
#endregion public int Connect()
{
Callback rasDialFunc = new Callback(RasManager.RasDialFunc);
RasDialParams.szEntryName += "\0";
RasDialParams.szUserName += "\0";
RasDialParams.szPassword += "\0";
int result = RasDial (0, null, ref RasDialParams, 0, rasDialFunc, ref
Connection);
return result;
} public static void RasDialFunc(uint unMsg, int rasconnstate, int dwError)
{
}
}
}An example of establishing a connection:RasManager myRas = new RasManager();
myRas.EntryName = "MyPhonebook entry"; // entry name in phonebook
myRas.UserName = "username";
myRas.Password = "password";
myRas.Connect().ToString();/***************************************************************************
*******Regards,Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Daniel Weber" <[email protected]>
>Newsgroups: microsoft.public.dotnet.languages.csharp
>Subject: Ras API
>Date: Sat, 17 Aug 2002 14:29:32 +0200
>Organization: T-Online
>Lines: 8
>Message-ID: <[email protected]>
>Mime-Version: 1.0
>Content-Type: text/plain; charset=ISO-8859-1
>Content-Transfer-Encoding: 8bit
>X-Trace: news.t-online.com 1029587368 02 26601 calPbRfGScAO0w 020817
12:29:28
>X-Complaints-To: [email protected]
>X-Sender: [email protected]
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
>Path:
cpmsftngxa06!tkmsftngp01!newsfeed00.sul.t-online.de!newsmm00.sul.t-online.co
m!t-online.de!news.t-online.com!not-for-mail
>Xref: cpmsftngxa06 microsoft.public.dotnet.languages.csharp:86230
>X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
>
>Can somebody provide some working code to access the ras api and detect
>connections?
>Thank you
>
>Daniel
>
>
>
>
有人用过这个吗?■■■■■ To teach a fish how to swim. ■■■■■
[DllImport("wininet.dll")]
public static extern bool InternetAutoDial(
[MarshalAs(UnmanagedType.U4) int dwFlags,
IntPtr hwndParent);