用C#在移动宽带api Windows 7和Windows 8上苦苦挣扎,不确定要安装什么 [英] struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install
问题描述
我有一个需要控制移动宽带API的应用程序.
我正在努力在自己的设备上正确安装api.
我一直按照本文档中的说明进行操作:
我已经能够从Visual Studio到V7.0/lib中的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上却可以,但是移动接口管理器为null = > mbnInfMgrInterface == null.
谢谢
不确定确切的内容,但是在与IMbnInterface和GetSignalStrength()纠缠之后(请参阅 请在此处查看答案:确定网络连接链接速度,这是您可以获得的属性列表: https://code.msdn.microsoft.com/windowsapps/network -information-sample-63aaa201 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: 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 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 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: 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 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
这篇关于用C#在移动宽带api Windows 7和Windows 8上苦苦挣扎,不确定要安装什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 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";
}
// ...
}
IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[];
Regtlibv12 Mbnapi.tlb
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"]);
}
}
Invalid query
message.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";
}
// ...
}