|
wince下手动cdma拨号成功,调用rasdial函数实现自动拨号提示691错误
[复制链接]
编程环境是vs2005,语言是c#,板子CDMA2440,实现自动拨号的函数如下:
//枚举可用的连接(在这里只有一个“我的连接”,手动可以连上)
public static RASENTRYNAME[] GetRASEntries()
{
RASENTRYNAME[] result = null;
int size = Marshal.SizeOf(typeof(RASENTRYNAME));
int Cb = size;//new IntPtr(size);
int cEntries = 0; //IntPtr.Zero;
IntPtr pEntries = IntPtr.Zero;
try
{
pEntries = Marshal.AllocHGlobal(Cb);
Marshal.Copy(BitConverter.GetBytes(size), 0, pEntries, 4);//pEntries->dwSize = size;
uint ret = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, pEntries, ref Cb, ref cEntries);
if (ret != 0) //ERROR_BUFFER_TOO_SMALL;ERROR_NOT_ENOUGH_MEMORY
{
if (pEntries != IntPtr.Zero)
{
Marshal.FreeHGlobal(pEntries);
}
pEntries = Marshal.AllocHGlobal(Cb);
Marshal.Copy(BitConverter.GetBytes(size), 0, pEntries, 4);//pEntries->dwSize = size;
}
ret = RasEnumEntries(IntPtr.Zero, IntPtr.Zero, pEntries, ref Cb, ref cEntries);
if (ret == 0) //SUCCESS
{
if (cEntries > 0)
{
result = CreateArrayOfType(pEntries, size, cEntries);
}
}
else
{
throw new Exception(string.Format("RasEnumEntries failed: Error {0}", ret));
}
}
finally
{
if (pEntries != IntPtr.Zero)
{
Marshal.FreeHGlobal(pEntries);
}
}
return result;
}
//拨号连接
public static void DialUp()
{
//check the connection state first
if (IntPtr.Zero != m_pRasSession)
{
RASCONNSTATE resConnState = (RASCONNSTATE)GetStatus();
if (RASCONNSTATE.RASCS_Connected == resConnState ||
RASCONNSTATE.RASCS_PortOpened == resConnState ||
RASCONNSTATE.RASCS_DeviceConnected == resConnState ||
RASCONNSTATE.RASCS_AllDevicesConnected == resConnState ||
RASCONNSTATE.RASCS_Authenticate == resConnState ||
RASCONNSTATE.RASCS_AuthAck == resConnState ||
RASCONNSTATE.RASCS_Authenticated == resConnState)
{
return;
}
}
RASDIALPARAMS rasDialParams = new RASDIALPARAMS();
rasDialParams.size = Marshal.SizeOf(rasDialParams);
rasDialParams.entryName = pEntryName//是上个函数返回的连接名字“我的连接”
rasDialParams.userName ="card"
rasDialParams.password = "card";
int lResult = RasDial(IntPtr.Zero, IntPtr.Zero, RASDIALPARAMS.ToBytes(rasDialParams), 0xFFFFFFFF, IntPtr.Zero, ref m_pRasSession);
if (lResult != 0)
{
throw new Exception(string.Format("RasDial failed: Error {0}", lResult));
}
}
程序运行以后提示错误号是691.网上的691错误解释是:因为用户名和/或密码在此域上无效,所以访问被拒绝。那么是域没有设置吗,但是我不知道域是多少啊。代码本身有什么错误么?求救各位大侠了。
|
|