首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“应用程序没有调用WSAStartup,或者WSAStartup失败”意味着什么?

“应用程序没有调用WSAStartup,或者WSAStartup失败”意味着什么?
EN

Stack Overflow用户
提问于 2012-09-22 08:48:07
回答 1查看 6.8K关注 0票数 2

我正在尝试开发通过网络连接到网络服务器的软件;一切正常工作,直到尝试使用软线来保护我的软件。我的dongle有一些网络特性,它的API工作在网络基础设施下。wWhen --我在我的程序中添加了Dongle检查代码--我得到了以下错误:

代码语言:javascript
复制
"Either the application has not called WSAStartup, or WSAStartup failed"  

我将抛出异常的代码块放入其中。我得到的例外情况是:我登录到程序(一切正常),然后插入dongle,然后程序停止并请求dongle,我再次插入dongle并尝试登录,但我在网上得到了一个异常。

响应= (HttpWebResponse)request.GetResponse();

代码语言:javascript
复制
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);
                }
EN

回答 1

Stack Overflow用户

发布于 2012-09-22 08:58:15

WSAStartup是套接字库中的第一个函数,它在开始使用net时执行。你可以进口

代码语言:javascript
复制
 [DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError=true)]
 static extern Int32 WSAGetLastError();

当引发异常时,执行WSAGetLastError并查看来自这里的错误代码。希望它能帮到你。在获得Win32Exception的特定情况下,您可以使用异常中的NativeErrorCode,如@Patrick在注释中所写。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12542287

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档