尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
   [STAThread]        [DllImport("sms.dll", EntryPoint = "Sms_Connection")]
        public static extern uint Sms_Connection(uint Com_Port, uint Com_BaudRate, out string Mobile_Type);        [DllImport("sms.dll", EntryPoint = "Sms_Disconnection")]
        public static extern uint Sms_Disconnection();        [DllImport("sms.dll", EntryPoint = "Sms_Send")]
        public static extern uint Sms_Send(string Sms_TelNum, string Sms_Text);        [DllImport("sms.dll", EntryPoint = "Sms_Receive")]
        public static extern uint Sms_Receive(string Sms_Type, out string Sms_Text);        [DllImport("sms.dll", EntryPoint = "Sms_Delete")]
        public static extern uint Sms_Delete(string Sms_Index);        [DllImport("sms.dll", EntryPoint = "Sms_AutoFlag")]
        public static extern uint Sms_AutoFlag();        [DllImport("sms.dll", EntryPoint = "Sms_NewFlag")]
        public static extern uint Sms_NewFlag();
        //如果连接成功返回true 否则返回false
        public bool SmsConn()
        {
            try
            {
                string TypeStr = "";
                if (Sms_Connection(uint.Parse(AddResource.SMSPORT), 9600, out TypeStr) == 1) ///5为串口号,0为红外接口,1,2,3,...为串口
                {
                    return true;
                }else {
                    return false;
                }
            }catch (Exception) {
                return false;
            }
        }

解决方案 »

  1.   

    我上次出现这个问题 是因为少写了个 ref 不知道你这个方法签名是否正确
      

  2.   

    //如果连接成功返回true 否则返回false
      public bool SmsConn()
      {
      try
      {
      string TypeStr = "";
      if (Sms_Connection(uint.Parse(AddResource.SMSPORT), 9600, out TypeStr) == 1) ///5为串口号,0为红外接口,1,2,3,...为串口
      {
      return true;
      }else {
      return false;
      }
      }catch (Exception) {
      return false;
      }
      }抛出的异常是 AcessViolationException   
    尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
      

  3.   

    尝试读取或写入受保护的内存。这通常指示其他内存已损坏一般是引用的类型不对或者没有加传递ref建议把SMS.DLL代码贴出来看看你什么地方外部引用不对了