C# Api调用的奇怪问题
以下是c版本的api原型,现在想用C#调用,其中倒数第二个参数(sMsgID)是带返回值的参数,怎么取得返回值
CNGPAPI_EXPORTS CNGPSendSingle(const int nMsgType, const int nNeedReport,
const int nMsgLevel,const char *sServiceID, const int nMsgFormat,
const char *sFeeType, int nFeeUserType,const char *sFeeCode,
const char *sValidTime, const char *sAtTime,
const char *sSrcTermID, const char *sChargeTermID, const char *sDestTermID,
const int nMsgLen,const char *sMsgContent,
char *sMsgID, int *nErrorCode);方法1:使用ref string类型代替char* sMsgID
[DllImport(@"C:\send\smgwapi.dll", EntryPoint = "CNGPSendSingle")]
unsafe public static extern int SendSingle(int nMsgType, int nNeedReport,
int nMsgLevel, string sServiceID, int nMsgFormat,
string sFeeType, int nFeeUserType, string sFeeCode,
string sValidTime, string sAtTime,
string sSrcTermID, string sChargeTermID, string sDestTermID,
int nMsgLen, string sMsgContent,
ref string sMsgID,ref int nErrorCode);
//调用实例
string msgid = new string('a', 10);
int r = SendSingle(nMsgType, nNeedReport, 1, sServiceID, nMsgFormat, sFeeType, nFeeUserType, sFeeCode, sValidTime, sAtTime, sSrcTermId, sChargeTermID, sDestTermID, sMsgContent.Length * 2, sMsgContent,ref msgid, ref errorcode);
string s = msgid;
MessageBox.Show("msgid:" + s + "\n返回值:" + r.ToString() + "\n" + "errorcode:" + errorcode.ToString());
这种方式中,取得了返回值,但返回值是乱码,请问这个调用哪里出错了