社区
C#
帖子详情
500分赠送
ikis
2003-09-29 06:20:58
在各种版本下 RasConn 应该怎么设置?C#的预处理命令怎么用?
请问调用在win2000下,为什么调用API 函数 RasEnumConnections是总是返回632,和调用API函数RasGetErrorString老是抛出ExecutionEngineException 异常。
...全文
97
8
打赏
收藏
500分赠送
在各种版本下 RasConn 应该怎么设置?C#的预处理命令怎么用? 请问调用在win2000下,为什么调用API 函数 RasEnumConnections是总是返回632,和调用API函数RasGetErrorString老是抛出ExecutionEngineException 异常。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
8 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
cnhgj
2003-09-30
打赏
举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics; // Debug, Trace
namespace RAS_Application
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtMain;
private System.Timers.Timer m_Timer;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public IntPtr m_Handle;
public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
// DoWork();
}
:
:
:
:
private void DoWork()
{
RAS ras =new RAS();
RASCONN lpRasConn =new RASCONN();
int lpcb =0;
int lpcConnections =0;
// lpRasConn = (LPRASCONN) GlobalAlloc(GPTR, sizeof(RASCONN));
// lpRasConn->dwSize = sizeof(RASCONN);
// lpcb = sizeof(RASCONN);
// ...SizeOf() ist 'unsafe' Code !!
lpRasConn.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(lpRasConn);
lpcb = lpRasConn.dwSize;
int nRet = RAS.API_RasEnumConnections(ref lpRasConn, ref lpcb, ref
lpcConnections);
if(nRet != 0)
{
Trace.WriteLine("RasEnumConnections failed: Error = " +nRet.ToString());
txtMain.Text +="RasEnumConnections failed: Error = " +nRet.ToString();
}
else
{
Trace.WriteLine("The following RAS connections are currently active\n\n");
for (int i = 0; i < lpcConnections; i++)
{
Trace.WriteLine("Entry name: " +lpRasConn.szEntryName);
txtMain.Text +="Entry name: " +lpRasConn.szEntryName +" ";
// lpRasConn++;
}
}
if(nRet == 0)
{
// Get the connection status.
RASCONNSTATUS RasStatus =new RASCONNSTATUS();
// RasStatus.dwSize = sizeof (RASCONNSTATUS);
RasStatus.dwSize = System.Runtime.InteropServices.Marshal.SizeOf(RasStatus);
int dwReturn = RAS.API_RasGetConnectStatus(lpRasConn.hrasconn, ref
RasStatus);
// If there is an error in getting the connection status
if(dwReturn != 0)
{
Trace.WriteLine("Failed getting connect status. Error : "
+dwReturn.ToString());
txtMain.Text +="Failed getting connect status. Error : "
+dwReturn.ToString();
}
else
{
Trace.WriteLine("Connect status : " +RasStatus.rasconnstate.ToString() +"
Device : " +RasStatus.szDeviceName);
txtMain.Text +="Connect status : " +RasStatus.rasconnstate.ToString() +"
Device : " +RasStatus.szDeviceName;
}
}
}
:
:
:
/// <summary>
/// Holt den Status der RAS-Verbindung
/// </summary>
public RASCONNSTATE GetConnStatus(IntPtr intRasConn)
{
int intRetcode =0;
RASCONNSTATE RASConnState =new RASCONNSTATE();
string strDeviceName =null;
string strDevicetype =null;
RASCONNSTATUS rasconnstatus95 =new RASCONNSTATUS();
rasconnstatus95.dwSize = 160;
try
{
intRetcode = RAS.API_RasGetConnectStatus(intRasConn, ref rasconnstatus95);
}
catch(Exception e)
{
Trace.WriteLine(e.Message.ToString());
txtMain.Text +="\r\nException: " +e.Message.ToString();
}
if(intRetcode != 0)
{
/*strDeviceName = "Not Available"
strDevicetype = "Not Available"
' lngRASErrorNumber = lngRetcode
' strRASDescription = lpRASError.fcnRASErrorString()
' fcnRASGetConnectionStatus = lngRetcode
*/
}
else
{
// success
RASConnState = rasconnstatus95.rasconnstate;
strDeviceName = rasconnstatus95.szDeviceName;
strDevicetype = rasconnstatus95.szDeviceType;
// fcnRASGetConnectionStatus = 0
}
Trace.WriteLine(strDeviceName +" " +strDevicetype);
txtMain.Text +="\r\nDevice-Name: " +strDeviceName +" Device-Typ: "
+strDevicetype;
return RASConnState;
}
private void OnTimerTick(object sender, System.Timers.ElapsedEventArgs e)
{
// int Handle =0;
// Trace.WriteLine("OnTimerTick()");
GetActiveConnection(ref m_Handle);
Trace.WriteLine("OnTimerTick(): " +m_Handle.ToString());
txtMain.Text +="\r\nOnTimerTick(): " +m_Handle.ToString();
GetConnStatus(m_Handle);
}
private string GetActiveConnection(ref IntPtr Handle)
{
RASCONN lprasconn =new RASCONN();
int lpcConnections =0;
int lpcb;
IntPtr hRasConn;
string NameRasConn;
lprasconn.dwSize = 412;
lpcb = 412; //256 * lprasconn[0].dwSize;
string ret = null;
/*
========== Exception Text ==========
System.NullReferenceException: Der Wert 'null' wurde gefunden, als eine
Objektinstanz erforderlich war.
at RAS_Application.RAS.API_RasEnumConnections(RASCONN& lprasconn, Int32&
lpcb, Int32& lpcConnections)
at RAS_Application.MainForm.GetActiveConnection(IntPtr& Handle) in c:\.net
tests\03.11\ras_application\mainform.cs:line 281
at RAS_Application.MainForm.OnTimerTick(Object sender, ElapsedEventArgs e)
in c:\.net tests\03.11\ras_application\mainform.cs:line 260
*/
if(RAS.API_RasEnumConnections(ref lprasconn, ref lpcb, ref lpcConnections)
== 0)
{
if(lpcConnections > 0) // Eine DFÜ-Netzwerkverbindung ist aktiv
{
hRasConn = lprasconn.hrasconn; // Handle der Verbindung
Handle = hRasConn;
NameRasConn = lprasconn.szEntryName.ToString();
NameRasConn = NameRasConn.PadRight(NameRasConn.IndexOf(NameRasConn));
NameRasConn.Trim();
Trace.WriteLine("Name RAS-Conection: " +NameRasConn);
txtMain.Text +="\r\nName RAS-Conection: " +NameRasConn;
if(NameRasConn.IndexOf("Direct Cable Connection") > 0)
{
return null;
}
ret = NameRasConn;
}
else
Handle = IntPtr.Zero;
Trace.WriteLine("in if(): API_RasEnumConnections() !=0");
txtMain.Text +="\r\nin if(): API_RasEnumConnections() !=0";
}
Trace.WriteLine("in if(): API_RasEnumConnections() ==0");
txtMain.Text +="\r\nin if(): API_RasEnumConnections() ==0 Phonebook: "
+lprasconn.szPhonebook;
return ret;
}
}
}
cnhgj
2003-09-30
打赏
举报
回复
一个例子,你参考一下
using System;
using System.Runtime.InteropServices; // [DllImport]
namespace RAS_Application
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct LUID
{
int LowPart;
long HighPart;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct RASCONN
{
public int dwSize;
public IntPtr hrasconn;
public string szEntryName;
// if(System.Environment.OSVersion >= 0x400)
//#if (WINVER >= 0x400)
public string szDeviceType;
public string szDeviceName;
//#endif
//#if (WINVER >= 0x401)
public string szPhonebook;
public int dwSubEntry;
//#endif
//#if (WINVER >= 0x500)
public Guid guidEntry;
//#endif
//#if (WINVER >= 0x501)
public int dwSessionId;
public int dwFlags;
public LUID luid;
//#endif
}
public enum RASCONNSTATE
{
RASCS_OpenPort = 0,
RASCS_PortOpened,
RASCS_ConnectDevice,
RASCS_DeviceConnected,
RASCS_AllDevicesConnected,
RASCS_Authenticate,
RASCS_AuthNotify,
RASCS_AuthRetry,
RASCS_AuthCallback,
RASCS_AuthChangePassword,
RASCS_AuthProject,
RASCS_AuthLinkSpeed,
RASCS_AuthAck,
RASCS_ReAuthenticate,
RASCS_Authenticated,
RASCS_PrepareForCallback,
RASCS_WaitForModemReset,
RASCS_WaitForCallback,
RASCS_Projected,
//#if (WINVER >= 0x400)
RASCS_StartAuthentication, // Windows 95 only
RASCS_CallbackComplete, // Windows 95 only
RASCS_LogonNetwork, // Windows 95 only
//#endif
RASCS_SubEntryConnected,
RASCS_SubEntryDisconnected,
RASCS_Interactive = 0x1000, // RASCS_PAUSED,
RASCS_RetryAuthentication,
RASCS_CallbackSetByCaller,
RASCS_PasswordExpired,
//#if (WINVER >= 0x500)
RASCS_InvokeEapUI,
//#endif
RASCS_Connected = 0x2000, //RASCS_DONE,
RASCS_Disconnected
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct RASCONNSTATUS
{
public int dwSize;
public RASCONNSTATE rasconnstate;
public int dwError;
public string szDeviceType;
public string szDeviceName;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct RASEAPINFO
{
public int dwSizeofEapInfo;
public byte [] pbEapInfo;
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct RASDIALEXTENSIONS
{
public int dwSize;
public int dwfOptions;
public int hwndParent;
public uint reserved;
//#if (WINVER >= 0x500)
public uint reserved1;
public RASEAPINFO RasEapInfo;
//#endif
}
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct RASDIALPARAMS
{
public int dwSize;
public string szEntryName;
public string szPhoneNumber;
public string szCallbackNumber;
public string szUserName;
public string szPassword;
public string szDomain;
//#if (WINVER >= 0x401)
public int dwSubEntry;
public uint dwCallbackId;
//#endif
}
/// <summary>
/// Summary description for RAS.
/// </summary>
public class RAS
{
[DllImport("Rasapi32.dll", EntryPoint="RasEnumConnectionsA",
SetLastError=true)]
internal static extern int API_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
);
[DllImport("Rasapi32.dll", EntryPoint="RasGetConnectStatus",
SetLastError=true)]
internal static extern int API_RasGetConnectStatus
(
IntPtr hrasconn, // handle to RAS connection of interest
ref RASCONNSTATUS lprasconnstatus
// buffer to receive status data
);
[DllImport("Rasapi32.dll", EntryPoint="RasDial", SetLastError=true)]
internal static extern int API_RasDial
(
ref RASDIALEXTENSIONS lpRasDialExtensions,
// pointer to function extensions data
ref string lpszPhonebook, // pointer to full path and file
// name of phone-book file
ref RASDIALPARAMS lpRasDialParams,
// pointer to calling parameters data
int dwNotifierType, // specifies type of RasDial event handler
ref IntPtr lpvNotifier, // specifies a handler for RasDial events
ref IntPtr lphRasConn // pointer to variable to receive
// connection handle
);
public RAS()
{
//
// TODO: Add constructor logic here
//
}
}
}
kuangren
2003-09-29
打赏
举报
回复
呵呵,这个不是很懂,帮你up好了~
kuangsha007
2003-09-29
打赏
举报
回复
关注,帮你顶
daou101
2003-09-29
打赏
举报
回复
建议把你的问题发给 思归
gz
冷月孤峰
2003-09-29
打赏
举报
回复
Mark
changezhong
2003-09-29
打赏
举报
回复
gz
noahart
2003-09-29
打赏
举报
回复
up~~~~~~~~
百度文库自动领取工具
+悬赏
分
回答被提问者采纳为最佳答案,或者通过投票被选为最佳答案,回答者可获得系统自动
赠送
的20
分
经验值和财富值+提问者设置的悬赏
分
文档操作 上传文档成功 (其他用户可见) +2
分
/份 标价非0
分
文档被别人...
旭荣加油站营销软件2017.5破解版
赠送
卡项目:比如
赠送
卡内有
500
元金额;柴油卡每次加油100抵扣3元,加200抵扣6元,以此类推;汽油卡每次加油100抵扣5元,加200抵扣10元,以此类推。
赠送
卡
赠送
给客户,客户一般不会拒绝,感觉里边是有金额,而且...
Vue+ES6全家桶入门基础与项目实战+
赠送
仿京东电商网站 2021新
本课程讲了Vue3+Vue2入门基础与实战,其中还重点讲解了ES6、TypeScript这些基础知识,实战是价值
500
0元的真实企业级项目---仿京东电商网站,同时项目代码全部
赠送
,还
赠送
前后端架构模板,工作中直接使用。...
视易神通夜总会5.0安装包
1.增加员工
赠送
限额,根据后台参数可配置为按日、周、月结算(按日结算时,每天做日结处理时更新已
赠送
金额为0,按周结算时,每周一做日结处理时更新已
赠送
金额为0,按月结算,每月1号做日结处理时更新已
赠送
金额为0...
宏杰网络虚拟主机实时开通系统 v2.2.
500
特别版
版本:2.2.
500
特别版 为了庆祝本主机程序注册数量超过1000人而特别制作的一个免费无站点限制版本 此版本只支持IMAIL邮局 可以
分
类开通ASP,PHP,.NET空间,空间到期自动停止,可以强制广告(HTML下),可以单独设置和...
C#
110,545
社区成员
642,581
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章