VB版的老大们,帮小弟看一下。还是VB调用VC DLL的问题,尝试多次无果。总是内存不能为"written"。函数原型:
int WINAPI CNGPSendSingle(
int nNeedReport,
int nMsgLevel,
const char* sServiceID,
int nMsgFormat,
const char* sFeeType,
const char* sFeeCode,
int nFeeUserType,
const char* sValidTime,
const char* sAtTime,
const char* sChargeTermID,
const char* sDestTermID,
int nMsgLen,
const char* sMsgContent,
char* sMsgID,
int* pnErrorCode,
BYTE* pnCongestionState
int nSubType,
const char* sSrcTermID );
我的声明:
Public Declare Function CNGPSendSingle Lib "CNGPDll.dll" (ByVal nNeedReport As Long, _
ByVal nMsgLevel As Long, _
ByVal sServiceID As String, _
ByVal nMsgFormat As Long, _
ByVal sFeeType As String, _
ByVal sFeeCode As String, _
ByVal nFeeUserType As Long, _
ByVal sValidTime As String, _
ByVal sAtTime As String, _
ByVal sChargeTermID As String, _
ByVal sDestTermID As String, _
ByVal nMsgLen As Long, _
ByVal sMsgContent As String, _
ByVal sMsgID As String, _
ByRef pnErrorCode As Long, _
ByVal pnCongestionState As Byte, _
ByVal nSubType As Long, _
ByVal sSrcTermID As String) As Long我的调用:
Dim ServiceID As String * 11
Dim FeeType As String * 3
Dim FeeCode As String * 7
Dim ValidTime As String * 18
Dim AtTime As String * 18
Dim ChargeTermID As String * 22
Dim DestTermID As String * 22
Dim MsgContent As String
Dim MsgID As String * 12
Dim ErrorCode As Long
Dim CongestionState As Byte
Dim SrcTermID As String * 22 ServiceID = "HELP" & Chr(0)
FeeType = "00" & Chr(0)
FeeCode = "000000" & Chr(0)
ValidTime = Chr(0)
AtTime = Chr(0)
ChargeTermID = Chr(0)
DestTermID = "03508827375" & Chr(0) 问题出在这里:如果是"8827375",就不会崩溃;如果是"03508827375",总是内存不能为"written"
MsgContent = "asd"
SrcTermID = "10680079" & Chr(0)MsgBox CNGPSendSingle(0, 0, ServiceID, _
15, FeeType, FeeCode, _
1, ValidTime, _
AtTime, ChargeTermID, _
DestTermID, 3, _
MsgContent, _
MsgID, ErrorCode, CongestionState, _
0, SrcTermID)
=========================================================================================
DestTermID = "03508827375" & Chr(0)
问题出在这里:如果是"8827375",就不会崩溃;
如果是"03508827375",总是内存不能为"written"
老大们帮小弟看一下,多谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
int WINAPI CNGPSendSingle(
int nNeedReport,
int nMsgLevel,
const char* sServiceID,
int nMsgFormat,
const char* sFeeType,
const char* sFeeCode,
int nFeeUserType,
const char* sValidTime,
const char* sAtTime,
const char* sChargeTermID,
const char* sDestTermID,
int nMsgLen,
const char* sMsgContent,
char* sMsgID,
int* pnErrorCode,
BYTE* pnCongestionState
int nSubType,
const char* sSrcTermID );
我的声明:
Public Declare Function CNGPSendSingle Lib "CNGPDll.dll" (ByVal nNeedReport As Long, _
ByVal nMsgLevel As Long, _
ByVal sServiceID As String, _
ByVal nMsgFormat As Long, _
ByVal sFeeType As String, _
ByVal sFeeCode As String, _
ByVal nFeeUserType As Long, _
ByVal sValidTime As String, _
ByVal sAtTime As String, _
ByVal sChargeTermID As String, _
ByVal sDestTermID As String, _
ByVal nMsgLen As Long, _
ByVal sMsgContent As String, _
ByVal sMsgID As String, _
ByRef pnErrorCode As Long, _
ByVal pnCongestionState As Byte, _
ByVal nSubType As Long, _
ByVal sSrcTermID As String) As Long我的调用:
Dim ServiceID As String * 11
Dim FeeType As String * 3
Dim FeeCode As String * 7
Dim ValidTime As String * 18
Dim AtTime As String * 18
Dim ChargeTermID As String * 22
Dim DestTermID As String * 22
Dim MsgContent As String
Dim MsgID As String * 12
Dim ErrorCode As Long
Dim CongestionState As Byte
Dim SrcTermID As String * 22 ServiceID = "HELP" & Chr(0)
FeeType = "00" & Chr(0)
FeeCode = "000000" & Chr(0)
ValidTime = Chr(0)
AtTime = Chr(0)
ChargeTermID = Chr(0)
DestTermID = "03508827375" & Chr(0) 问题出在这里:如果是"8827375",就不会崩溃;如果是"03508827375",总是内存不能为"written"
MsgContent = "asd"
SrcTermID = "10680079" & Chr(0)MsgBox CNGPSendSingle(0, 0, ServiceID, _
15, FeeType, FeeCode, _
1, ValidTime, _
AtTime, ChargeTermID, _
DestTermID, 3, _
MsgContent, _
MsgID, ErrorCode, CongestionState, _
0, SrcTermID)
=========================================================================================
DestTermID = "03508827375" & Chr(0)
问题出在这里:如果是"8827375",就不会崩溃;
如果是"03508827375",总是内存不能为"written"
老大们帮小弟看一下,多谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
解决方案 »
- 如何保存鼠标键盘回放信息到文件?
- 关于打包的问题,请过来发表一下自己的看法,有道理的,马上给分,不够再加
- 用TreeView實現文件夾和它裏面的文件,要原碼
- 如何满足多项条件
- ★申请过《软件著作权》的前辈请进来一下★
- 如何写带参数的程序 如: x:\mm\mm.exe -h 该如何写代码实现带参数-h时的功能
- 调用mkdir等系统命令时,如何得到返回值?
- 求在win2000下使用RegSetValueEx成功的范例或代码
- (62分)编写DLL时遇到的问题,请高手指点!
- vb开发cad技术之vb链接cad
- VC编写的DLL给VB调用,输出字符串的时候为什么字符串会有尾巴呢
- sos 数据库连接问题
int WINAPI CNGPSendSingle(
int nNeedReport,
int nMsgLevel,
const char* sServiceID,//[11]: this stands for the string has 11B space;
int nMsgFormat,
const char* sFeeType, //[3]
const char* sFeeCode, //[7]
int nFeeUserType, //[7]
const char* sValidTime, //[18]
const char* sAtTime, //[18]
const char* sChargeTermID, //[22]
const char* sDestTermID, //[22]
int nMsgLen,
const char* sMsgContent,
char* sMsgID, //[11]
int* pnErrorCode,
BYTE* pnCongestionState,
int nSubType, //[2]
const char* sSrcTermID //[22]
);
int* pnErrorCode,
BYTE* pnCongestionState以上三个字段为返回值。
Dim DestTermID(22-1) As byte
当然,你的声明也要改一下
ByVal sDestTermID As String
修改为:
sDestTermID As any(或者as byte)
调用时,传入数组的首个元素DestTermID(0)
int* pnErrorCode,
BYTE* pnCongestionState以上三个字段为返回值。
--------------------------------
既然这三个字段为返回值,那么在函数声明中都应该为ByRef引用啊,你的声明中好像不是。
声明更改
ByVal pnErrorCode As Long, _
ByRef pnCongestionState As Byte, _
多谢 暴风雨 老大。