使用 C# 在移动宽带 api windows 7 和 windows 8 上苦苦挣扎,不知道要安装什么 [英] struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install

查看:25
本文介绍了使用 C# 在移动宽带 api windows 7 和 windows 8 上苦苦挣扎,不知道要安装什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序需要控制移动宽带 API.

我正在努力在我的设备上正确安装 api.

我一直按照本文档中的说明进行操作:

http://www.google.be/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F7%2FE%2F7%2F7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2%2FMB_3A%2F%2Fdownload.microsoft.com%2Fdownload%2F7%2FE%2F7%2F7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2%2FMB_Vmupoge7D;usg=AFQjCNG6yaGf4sRhdbWI99fE7tmQX8cmnA&sig2=2Fg-_DRYBIselKR19wTq2Q

并尝试将这些步骤与此 stackoverflow 解释结合起来

C# 读取 Windows Mobile 宽带连接属性

我已经能够在 V7.0/lib 中建立从 Visual Studio 到 mbnapi.tlb 的参考.现在我的 obj/debug 文件夹中自动有一个 interop.mbnapi.tlb.

尝试检查 SIM 卡是否已插入并正常工作/已激活"时.=> 我的代码在以下行崩溃

IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];

当我在 Windows 8 上运行它时,mbnInfMgrInterface == null

我已经尝试在 Windows 8 上安装相同的 SDK,如文档要求中所述,但 SDK 仅适用于 Windows 7...

我尝试通过执行在 Windows 8 中注册 mbnapi

Regtlibv12 Mbnapi.tlb

没有任何运气...

我需要做什么才能让它工作?

有人有这方面的经验吗?

编辑.在 Windows 7(我的开发机器)上,我收到消息设备未准备好",我认为这是正常的,因为我没有移动宽带,在 Windows 8 上我有,但移动界面管理器为空 => mbnInfMgrInterface == null.

谢谢,

解决方案

不确定您到底在追求什么,但在与 IMbnInterface 和 GetSignalStrength() 斗争之后(请参阅 https://msdn.microsoft.com/en-us/library/windows/desktop/dd323166(v=vs.85).aspx) 并没有成功,我发现你可以使用 WMI 获取很多信息:

 int maxBandwidth = 0;string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface";ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query);ManagementObjectCollection moCollection = moSearch.Get();foreach(moCollection 中的管理对象 mo){if (Convert.ToInt32(mo["CurrentBandwidth"]) > maxBandwidth){//您可能想要使用 BytesReceivedPerSec 而不是 CurrentBandwidthmaxBandwidth = Convert.ToInt32(mo["CurrentBandwidth"]);}}

请在此处查看答案:确定网络连接链接速度,这里是您可以获得的属性列表:https://msdn.microsoft.com/en-us/library/aa394293(VS.85).aspx

更新:

请注意,我可以在 Windows 7 或 Windows 8.1 上的 Visual Studio 2015 中构建和调试上述代码(作为更大的 WPF 应用程序的一部分),并且我可以将相同的应用程序部署到它成功运行的 Windows 7 上.出于某种原因,当我在 Windows 8.1 上部署此应用程序时,我收到一条 Invalid query 消息.

更新 2:

请注意,我发现您无法像在 Windows 7 中那样在 Windows 8.1 中获取网络信息,因为 System.Management 命名空间在 Windows 8.1 上不可用.请参阅 https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201

 string connectionProfileInfo = string.Empty;ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();如果(InternetConnectionProfile == null){rootPage.NotifyUser("未连接到 Internet\n", NotifyType.StatusMessage);}别的{connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);OutputText.Text = connectionProfileInfo;rootPage.NotifyUser("成功", NotifyType.StatusMessage);}//调用这个函数,它允许你确定信号的强度和相关的带宽字符串 GetConnectionProfile(ConnectionProfile connectionProfile){//...如果 (connectionProfile.GetSignalBars().HasValue){connectionProfileInfo += "======================\n";connectionProfileInfo += "信号条:" + connectionProfile.GetSignalBars() + "\n";}//...}

I have an application that requires to control mobile broadband API.

I am struggling on correctly installing the api on my devices.

I've been follow the instructions in this document:

http://www.google.be/url?sa=t&rct=j&q=&esrc=s&frm=1&source=web&cd=1&cad=rja&ved=0CC0QFjAA&url=http%3A%2F%2Fdownload.microsoft.com%2Fdownload%2F7%2FE%2F7%2F7E7662CF-CBEA-470B-A97E-CE7CE0D98DC2%2FMB_ManagedCode.docx&ei=kyvmUs7jE4e60QWbooHYDg&usg=AFQjCNG6yaGf4sRhdbWI99fE7tmQX8cmnA&sig2=2Fg-_DRYBIselKR19wTq2Q

and trying to combine the steps with this stackoverflow explanation

C# Read Windows Mobile Broadband connection properties

I have been able to lay a reference from visual studio to mbnapi.tlb in V7.0/lib. and I automatically now have a interop.mbnapi.tlb in my obj/debug folder.

When trying to "check the SIM is inserted and working / activated". => my code crashes on the following line

IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];

When I run it on windows 8, mbnInfMgrInterface == null

I have already tried to install the same SDK on windows 8 as stated in the requirements of the document but the SDK is only meant for windows 7...

I have tried to register the mbnapi in windows 8 by performing

Regtlibv12 Mbnapi.tlb

no luck whatsoever...

what do I need to do to get this to work please?

anyone has some experience in this?

EDIT. on windows 7 (my development machine), I get the message "Device not ready", I think this is normal because I don't have mobile broadband on it, on windows 8 I do, but there the mobile interface manager is null => mbnInfMgrInterface == null.

thank you,

解决方案

Not sure exactly what you are after, but after struggling with IMbnInterface and GetSignalStrength() (see https://msdn.microsoft.com/en-us/library/windows/desktop/dd323166(v=vs.85).aspx) and being unsuccessful, I found that you can obtain a lot of info using WMI:

        int maxBandwidth = 0;
        string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface";
        ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query);
        ManagementObjectCollection moCollection = moSearch.Get();
        foreach (ManagementObject mo in moCollection)
        {
            if (Convert.ToInt32(mo["CurrentBandwidth"]) > maxBandwidth)
            {
                // Instead of CurrentBandwidth you may want to use BytesReceivedPerSec
                maxBandwidth = Convert.ToInt32(mo["CurrentBandwidth"]);
            }
        }

Please see answer here: Determining the network connection link speed and here is the list of properties you can obtain: https://msdn.microsoft.com/en-us/library/aa394293(VS.85).aspx

UPDATE:

Please note that I can build and debug the above code (as part of a larger WPF application) from within Visual Studio 2015 on either Windows 7 or Windows 8.1, and I can deploy the same application onto Windows 7 where it runs successfully. For some reason when I deploy this application on Windows 8.1, I get an Invalid query message.

UPDATE 2:

Please note that I found you cannot get the network info in Windows 8.1 in the same way as you do in Windows 7, in that the System.Management namespace is not available on Windows 8.1. See https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201

        string connectionProfileInfo = string.Empty;
        ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

        if (InternetConnectionProfile == null)
        {
            rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage);
        }
        else
        {
            connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile);
            OutputText.Text = connectionProfileInfo;
            rootPage.NotifyUser("Success", NotifyType.StatusMessage);
        }

        // Which calls this function, that allows you to determine how strong the signal is and the associated bandwidth
        string GetConnectionProfile(ConnectionProfile connectionProfile)
        {
            // ...
                if (connectionProfile.GetSignalBars().HasValue)
                {
                    connectionProfileInfo += "====================\n";
                    connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n";
                }
            // ...
        } 

这篇关于使用 C# 在移动宽带 api windows 7 和 windows 8 上苦苦挣扎,不知道要安装什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆