struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install

泄露秘密 提交于 2019-12-12 13:55:22

问题


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,


回答1:


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";
                }
            // ...
        } 


来源:https://stackoverflow.com/questions/21377811/struggling-with-mobile-broadband-api-windows-7-and-windows-8-with-c-not-sure-w

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!