 悬赏园豆:100
                [已关闭问题]
                悬赏园豆:100
                [已关闭问题] 
            
                 
        C语言函数声明为: 
bool bSendMsg(HANDLE hComm,char *szMsg,char *szPhNbr,char *szSCA,int iSMSFormat,char *szNextMsg,char *szErrInfo); 
入口参数:hComm 串口句柄,szMsg 待发的短信内容,szSCA 短信中心号码,iSMSFormat 短信编码格式 
出口参数:szNextMsg 超长部分的待发内容, sErrInfo 出错信息 
其中szSCA是结构体 
struct STRUCommInfo 
{ 
      int iBaudRate; 
      char szSCA[30]; 
}; 
我的c#声明为 
[DllImport("SMSCom.dll", EntryPoint = "bSendMsg")] 
public static extern bool bSendMsg(IntPtr hComm,string szMsg,string szPhNbr,string szSCA,int iSMSFormat,  StringBuilder szNextMsg, StringBuilder szErrInfo); 
    
结构体为: 
[StructLayout(LayoutKind.Sequential)] 
    public struct STRUCommInfo 
    { 
      public  int iBaudRate; 
      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]    
      public string szSCA; 
    } 
调用方法: 
其中stru.szSCA通过上个函数调用,已返回 “8613800555500” 
CallDll.bSendMsg(ptr, "在干嘛呢", "15215553319", stru.szSCA, 0, sd, sc); 
然后报:尝试读取或写入受保护的内存错误,期待高手看下我的代码参数是否传错了
bSendMsg中用到的变量被delete了,
把bSendMsg函数中所有变量,都定义成类的成员.(DLL中的变量和C#中的变量)
C不识别C#的StringBuilder