2017-06-09 115 views
0

我创造了一个关于测试文件MbnApi.dll程序,这是我的代码:System.AccessViolationException:试图读取或写入受保护的内存。使用MbnApi.dll

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using MbnApi; 

namespace TestMbnApi 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager(); 
      IMbnInterfaceManager infMgr = mbnInfMgr as IMbnInterfaceManager; 
      IMbnConnectionManager conManager = (IMbnConnectionManager)new MbnConnectionManager(); 
      // Connection 
      IMbnConnection[] connections = conManager.GetConnections(); 
      IMbnConnection con = connections.First(); 
      // Get interfaceID 
      String interfaceID = con.InterfaceID; 
      Console.WriteLine("InterfaceID : {0}", interfaceID); 
      // Get interface 
      IMbnInterface interfa = infMgr.GetInterface(interfaceID) as IMbnInterface; 
      // GetInterfaceCapability 
      MBN_INTERFACE_CAPS caps = interfa.GetInterfaceCapability(); 
      Console.WriteLine("Caps :{0}", caps); 

      Console.ReadLine(); 
     } 
    } 
} 

当我建立到文件.exe和笔记本电脑Windows上运行10 &有SIM卡3G。

Unhandled exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. 
    at System.StubHelpers.ValueClassMarshaler.ConvertToManaged(IntPtr dst, IntPtr src, IntPtr pMT) 
    at MbnApi.IMbnInterface.GetInterfaceCapability() 
    at TestMbnApi.Program.Main(String[] args) 

我使用Frameword 4.6.1的.Net和Visual Studio 2015年社区版本有:然后我接到错误。我不明白为什么这个程序错误?有没有人可以支持我这件事。 谢谢大家!

+0

错误发生在哪里?你有没有尝试捕捉异常? –

+0

如果我想访问'IMbnInterface'的属性,比如'GetHomeProvider',我有同样的问题。你解决了你的问题吗? – creg

+0

我很高兴你找到了解决方案,但请在发布之前先研究一下问题。还有一件事,'MbiApi'不适用于所有人,因此这段代码不会编译。如果您使用特殊API继续前进,请提供其他人下载的链接。另外,3G sim与代码有什么关系。好的信息应该是OS + 64或32位。示例Win-x86或Win-x64。 –

回答

0

我刚刚解决了这个问题。 要解决此问题,请使用与您正在使用的操作系统相对应的MbnApi.dll。我正在使用窗口10,并为此操作构建了MbnApi.dll。 要建立MbnApi.dll,我已经得到了窗口SDK版本10以下链接如下: [https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk][1]

下载窗口SDK后,请访问文件夹: C:\ Program Files文件(x86)的\的Windows套件\ 10 \ Lib \ winv6.3 \ um \ x64 然后将文件mbnapi.tlb复制到包含文件TlbImp.exe的文件夹中。 并访问该文件夹并运行命令: TlbImp.exe mbnapi.tlb /out:MbnApi.dll 因此,您成功构建MbnApi.dll。

如果您有问题或成功,请尝试并反馈给我。

谢谢&最好注意,

相关问题