解决方案 »

  1.   

    char *的参数,如是传入,就用string,传出用StringBuilder,另外,CharSet = CharSet.Ansi或Auto
      

  2.   

    extern static int SMGPSendSingle(..., StringBuilder sMsgID, ref int nErrorCode);
      

  3.   

    /// Return Type: int
        ///nNeedReply: int
        ///nMsgLevel: int
        ///sServiceID: char*
        ///nMsgFormat: int
        ///sFeeType: char*
        ///sFeeCode: char*
        ///sValidTime: char*
        ///sAtTime: char*
        ///sChargeTermID: char*
        ///sDestTermID: char*
        ///sReplyPath: char*
        ///nMsgLen: int
        ///sMsgContent: char*
        ///sMsgID: char*
        ///nErrorCode: int*
        [System.Runtime.InteropServices.DllImportAttribute("<Unknown>", EntryPoint="SMGPSendSingle", CallingConvention=System.Runtime.InteropServices.CallingConvention.StdCall)]
    public static extern  int SMGPSendSingle(int nNeedReply, int nMsgLevel, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sServiceID, int nMsgFormat, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sFeeType, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sFeeCode, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sValidTime, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sAtTime, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sChargeTermID, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sDestTermID, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sReplyPath, int nMsgLen, [System.Runtime.InteropServices.InAttribute()] [System.Runtime.InteropServices.MarshalAsAttribute(System.Runtime.InteropServices.UnmanagedType.LPStr)] string sMsgContent, System.IntPtr sMsgID, ref int nErrorCode) ;
    sMsgID指向内存的所有权不明,暂时用System.IntPtr(也就是.Net里面的void*)列集。
      

  4.   

    如问题在 最后两个参数里面,最后两个参数都是需要修改值的所以char *sMsgID  = StringBuild sMsgID 
    int *nErrorCode = ref int nErrorCode