关于C#调用C写的Dll的问题
mast 2007-12-19 11:04:49 C API声明如下:
int WINAPI SMGPSendSingle(
int nNeedReport,
int nMsgLevel,
const char* sServiceID,
int nMsgFormat,
const char* sFeeType,
const char* sFeeCode,
const char* sFixedFee,
const char* sValidTime,
const char* sAtTime,
const char* sSrcTermID,
const char* sChargeTermID,
const char* sDestTermID,
int nMsgLen,
const char* sMsgContent,
char* sMsgID,
int* pnErrorCode,
char* pMsgType = NULL,
char* pReserved = NULL,
const int* pTP_pid = NULL,
const int* pTP_udhi = NULL,
const char* pLinkID = NULL,
const char* pMsgSrc = NULL,
const int* pChargeUserType = NULL,
const int* pChargeTermType = NULL,
const char* pChargeTermPseudo =NULL,
const int* pDestTermType = NULL,
const char* pDestTermPseudo = NULL,
const int* pPkTotal = NULL,
const int* PkNumber = NULL,
const int* pSubmitMsgType = NULL,
const int* pSPDealResult = NULL,
const char* pMServiceID = NULL
);
我用C#写的调用代码如下:
[DllImport("SmgpDll.dll", EntryPoint = "SMGPSendSingle")]
private static extern int SMGPSendSingle(
int nNeedReport,int nMsgLevel,string sServiceID,int nMsgFormat,string sFeeType,string sFeeCode, //[7]
string sFixedFee,string sValidTime,string sAtTime,string sSrcTermID,string sChargeTermID, //[22]
string sDestTermID,int nMsgLen,string sMsgContent,
[Out]StringBuilder sMsgID, ref int pnErrorCode, StringBuilder pMsgType, StringBuilder pReserved, ref int pTP_pid,
ref int pTP_udhi, string pLinkID, string pMsgSrc, ref int pChargeUserType,
ref int pChargeTermType, string pChargeTermPseudo, ref int pDestTermType, string pDestTermPseudo,
ref int pPkTotal, ref int PkNumber, ref int pSubmitMsgType, ref int pSPDealResult, string pMServiceID);
每次调用就报"尝试读取或写入受保护的内存。这通常指示其他内存已损坏。"
请高手解答