尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
[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;
}
}
[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;
}
}
解决方案 »
- 怎么把下面代码换成存储过程来处理?不会用那些declare呀之类的东西
- 有比timer刷新还快的办法么
- winform问题 帮忙解决一下
- 救命:请问为什么用SqlDataReader从数据库中用GetFloat(3)总是说报异常“指定的转换无效。”
- 如何实现读取某个路径的文本内容
- JDBC和ADO.NET的比较
- 我想实现在richtextbox中的text内容写到pdf文件中,......请高手帮我解决该问题
- C#条形码打印出来后没有切断 / 打印条形码的代码
- 可以把一张表绑定到一个listview控件中吗?如何绑定?
- 页面权限设置,各位请帮帮忙
- C# , 一句话的解释,请指教
- VS建立新的项目时,如何让它初始的字体为微软雅黑,而不是宋体?
资源那里搜索一下。sms就可以搜到。
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
尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
有可能是out string这里有问题吧,改成StringBuilder试试。。
定义个StringBuilder sb = new StringBuilder(500)试试咯