我正在尝试开发通过网络连接到网络服务器的软件;一切正常工作,直到尝试使用软线来保护我的软件。我的dongle有一些网络特性,它的API工作在网络基础设施下。wWhen --我在我的程序中添加了Dongle检查代码--我得到了以下错误:
"Either the application has not called WSAStartup, or WSAStartup failed" 我将抛出异常的代码块放入其中。我得到的例外情况是:我登录到程序(一切正常),然后插入dongle,然后程序停止并请求dongle,我再次插入dongle并尝试登录,但我在网上得到了一个异常。
响应= (HttpWebResponse)request.GetResponse();
DongleService unikey = new DongleService();
checkDongle = unikey.isConnectedNow();
if (checkDongle)
{
isPass = true;
this.username = txtbxUser.Text;
this.pass = txtbxPass.Text;
this.IP = combobxServer.Text;
string uri = @"https://" + combobxServer.Text + ":5002num_events=1";
request = (HttpWebRequest)WebRequest.Create(uri);
request.Proxy = null;
request.Credentials = new NetworkCredential(this.username, this.pass);
ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
response = (HttpWebResponse)request.GetResponse();
Properties.Settings.Default.User = txtbxUser.Text;
int index = _servers.FindIndex(p => p == combobxServer.Text);
if (index == -1)
{
_servers.Add(combobxServer.Text);
Config_Save.SaveServers(_servers);
_servers = Config_Save.LoadServers();
}
Properties.Settings.Default.Server = combobxServer.Text;
// also save the password
if (checkBox1.CheckState.ToString() == "Checked")
Properties.Settings.Default.Pass = txtbxPass.Text;
Properties.Settings.Default.settingLoginUsername = this.username;
Properties.Settings.Default.settingLoginPassword = this.pass;
Properties.Settings.Default.settingLoginPort = "5002";
Properties.Settings.Default.settingLoginIP = this.IP;
Properties.Settings.Default.isLogin = "guest";
Properties.Settings.Default.Save();
response.Close();
request.Abort();
this.isPass = true;
this.Close();
}
else
{
MessageBox.Show("Please Insert Correct Dongle!", "Dongle Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}发布于 2012-09-22 08:58:15
WSAStartup是套接字库中的第一个函数,它在开始使用net时执行。你可以进口
[DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError=true)]
static extern Int32 WSAGetLastError();当引发异常时,执行WSAGetLastError并查看来自这里的错误代码。希望它能帮到你。在获得Win32Exception的特定情况下,您可以使用异常中的NativeErrorCode,如@Patrick在注释中所写。
https://stackoverflow.com/questions/12542287
复制相似问题