环境:VS 2005
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")]
public static extern int SMGPSendSingle
(
int nNeedReport,
int nMsgLevel,
string sServiceID,
int nMsgFormat,
string sFeeType,
string sFeeCode,
string sFixedFee,
string sValidTime,
string sAtTime,
string sSrcTermID,
string sChargeTermID,
string sDestTermID,
int nMsgLen,
string sMsgContent,
StringBuilder sMsgID,
out int pnErrorCode,
string pMsgType,
string pReserved,
int pTP_pid,
int pTP_udhi,
string pLinkID,
string pMsgSrc,
int pChargeUserType,
int pChargeTermType,
string pChargeTermPseudo,
int pDestTermType,
string pDestTermPseudo,
int pPkTotal,
int PkNumber,
int pSubmitMsgType,
int pSPDealResult,
string pMServiceID
);但是调用的时候就出现 "尝试读取或写入受保护的内存。这通常指示其他内存已损坏。",的错误,我把 string pMsgType, string pReserved, 改成StringBuilder还是出现同样错误,望高手指点一下,万分感谢
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")]
public static extern int SMGPSendSingle
(
int nNeedReport,
int nMsgLevel,
string sServiceID,
int nMsgFormat,
string sFeeType,
string sFeeCode,
string sFixedFee,
string sValidTime,
string sAtTime,
string sSrcTermID,
string sChargeTermID,
string sDestTermID,
int nMsgLen,
string sMsgContent,
StringBuilder sMsgID,
out int pnErrorCode,
string pMsgType,
string pReserved,
int pTP_pid,
int pTP_udhi,
string pLinkID,
string pMsgSrc,
int pChargeUserType,
int pChargeTermType,
string pChargeTermPseudo,
int pDestTermType,
string pDestTermPseudo,
int pPkTotal,
int PkNumber,
int pSubmitMsgType,
int pSPDealResult,
string pMServiceID
);但是调用的时候就出现 "尝试读取或写入受保护的内存。这通常指示其他内存已损坏。",的错误,我把 string pMsgType, string pReserved, 改成StringBuilder还是出现同样错误,望高手指点一下,万分感谢
解决方案 »
- gridview超链接传值
- C#写个小程序检测计算机是否安装Framework
- 请问系统中的某个指定程序出现出错退出的情况,能否写程序捕获这一信息
- c#向Mysql中插入数据乱码?
- 用VS2008写的网站。HTML页用JQUERY的AJAX访问ASPX页面。发布到IIS后不执行访问
- this.listView2 = this.listView1; 是传值还是传引用?
- 执行下面代码结果不是自己想的:预想的是生成一个Y20100525000002.DBF;结果生成的是Y2010052.DBF!
- C# Winform读数据库并显示在对应文本框中
- 如何读取行合并过的excel
- 下拉列表
- 如何改变MessageBox大小,项目画面大小1280*1024,弹出的框太小了...回后马上结帖给分.
- (1)byte[] 如何转换成string (2)File.Encrypt(path)加密为何无效?
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
);
char* -> StringBulder
我马上试验,我先问下 char* 我都用 StringBulder 替换试验过,const char* 我用string,考虑到这个数据不会改变。const int* 用 int 应该也是可以的吧?也是不能改变的
public static extern int SMGPSendSingle
(
int nNeedReport,
int nMsgLevel,
string sServiceID,
int nMsgFormat,
string sFeeType,
string sFeeCode,
string sFixedFee,
string sValidTime,
string sAtTime,
string sSrcTermID,
string sChargeTermID,
string sDestTermID,
int nMsgLen,
string sMsgContent,
StringBuilder sMsgID,
IntPtr 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
);
StringBuilder sMsgID,
IntPtr pnErrorCode,with
[Out]StringBuilder sMsgID,
ref int pnErrorCode,//Call
StringBuilder sMsgID = new StringBuilder(256);//Init it