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"
老大们帮小弟看一下,多谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    这是VC中的范例声明:
    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]
    );
      

  2.   

    char* sMsgID,
    int* pnErrorCode,
    BYTE* pnCongestionState以上三个字段为返回值。
      

  3.   

    估计是vb的字串的定义问题,建议类似这样定义,以DestTermID为例:
    Dim DestTermID(22-1) As byte
    当然,你的声明也要改一下
    ByVal sDestTermID As String
    修改为:
    sDestTermID As any(或者as byte)
    调用时,传入数组的首个元素DestTermID(0)
      

  4.   

    char* sMsgID,
    int* pnErrorCode,
    BYTE* pnCongestionState以上三个字段为返回值。
    --------------------------------
    既然这三个字段为返回值,那么在函数声明中都应该为ByRef引用啊,你的声明中好像不是。
      

  5.   

    问题已自己解决。解决如下:
    声明更改
    ByVal pnErrorCode As Long, _
    ByRef pnCongestionState As Byte, _
    多谢 暴风雨 老大。