这是API最常遇到的问题--声明类型转换的问题!!!
如下一个C语言API声明,如何转化为VB声明?转化之后又如何引用呢??请指点。
-------------------------------
typedef struct
{
char sMsgID[10+1];
int nErrorCode;
char sPhoneNo[21+1];
}SendBatchResp;typedef struct
{
int nMT_TLMsg;
int nMT_TLusr;
int nMT_Scs;
int nMT_WT;
int nMT_FL;
int nMO_Scs;
int nMO_WT;
int nMO_FL;
}QueryResp;typedef struct
{
unsigned int nIsReport;
unsigned int nMsgFormat;
unsigned int nMsgLength;
char sMsgID[10+1];
char sRecvTime[14+1];
char sSrcTermID[21+1];
char sDestTermID[21+1];
char sMsgContent[252+1];
}DeliverResp;SMGPAPI_EXPORTS InitSMGPAPI(const char *sINIFile);
SMGPAPI_EXPORTS SMGPSendSingle( const int nNeedReply, const int nMsgLevel,
const char *sServiceID, const int nMsgFormat,
const char *sFeeType, const char *sFeeCode, const char *sFixedFee,
const char *sValidTime, const char *sAtTime,
const char *sChargeTermID, const char *sDestTermID,
const char *sReplyPath, const int nMsgLen,
const char *sMsgContent,char *sMsgID, 
int *nErrorCode,const int nMsgType);
SMGPAPI_EXPORTS SMGPSendBatch( const int nNeedReply, const int nMsgLevel,
const char *sServiceID, const int nMsgFormat,
const char *sFeeType, const char *sFeeCode,const char *sFixedFee,
const char *sValidTime, const char *sAtTime,
const char *sChargeTermID, const char *sDestTermIDFile,
const char *sReplyPath, const int nMsgLen,
const char *sMsgFile, const char *sMsgIDFile,const int nMsgType);SMGPAPI_EXPORTS GetSendBatchResp(char *sMsgIDFile, int nPos, SendBatchResp *pSendBatchResp);SMGPAPI_EXPORTS SMGPDeliver(const int nTimeoutIn, DeliverResp *pDeliverResp);SMGPAPI_EXPORTS SMGPActiveTest(int *nErrorCode);

解决方案 »

  1.   

    typedef struct
    {
    char sMsgID[10+1];
    int nErrorCode;
    char sPhoneNo[21+1];
    }SendBatchResp;->type SendBatchResp
            sMsgID string*(10+1)
        nErrorCode integer
          sPhoneNo string*(21+1)
    end type
      

  2.   

    typedef struct
    {
    int nMT_TLMsg;
    int nMT_TLusr;
    int nMT_Scs;
    int nMT_WT;
    int nMT_FL;
    int nMO_Scs;
    int nMO_WT;
    int nMO_FL;
    }QueryResp;->
    type QueryResp
      nMT_TLMsg as long
      nMT_TLusr as long
      nMT_Scs as long
      nMT_WT as long
      nMT_FL as long
      nMO_Scs as long
      nMO_WT as long
      nMO_FL as longend type
      

  3.   

    API parameter typesC language data type In Visual Basic declare as Call with ATOM      ByVal variable As Integer An expression that evaluates to an Int. BOOL      ByVal variable As Long An expression that evaluates to a Long BYTE      ByVal variable As Byte An expression that evaluates to a Byte CHAR      ByVal variable As Byte An expression that evaluates to a Byte COLORREF  ByVal variable As Long An expression that evaluates to a Long DWORD     ByVal variable As Long An expression that evaluates to a Long HWND, HDC, HMENU, etc. (Windows handles) ByVal variable As Long An expression that evaluates to a Long INT, UINT ByVal variable As Long An expression that evaluates to a Long LONG      ByVal variable As Long An expression that evaluates to a Long LPARAM    ByVal variable As Long An expression that evaluates to a Long LPDWORD   variable As Long An expression that evaluates to a Long LPINT, LPUINT variable As Long An expression that evaluates to a Long LPRECT variable As type Any variable of that user-defined type LPSTR, LPCSTR ByVal variable As String An expression that evaluates to a String LPVOID variable As Any Any variable (use ByVal when passing a string) LPWORD variable As Integer An expression that evaluates to an Int. LRESULT ByVal variable As Long An expression that evaluates to a Long NULL As Any or ByVal variable As Long ByVal Nothing or ByVal 0& or vbNullString SHORT     ByVal variable As Integer An expression that evaluates to an Int. VOID      Sub procedure Not applicable WORD      ByVal variable As Integer An expression that evaluates to an Int. WPARAM    ByVal variable As Long An expression that evaluates to a Long 
      

  4.   

    大家都解决了最简单的问题,关键问题怎么不动呢?
    关键是const  char  *sValidTime,  int  *nErrorCode等问题,而且还要解决如何引用并赋值的问题,大家继续啊!~高手大侠请不要手下留情哦!该出手时就出手!
      

  5.   

    const  char  *sValidTime
      dim sValidTime() as stringint  *nErrorCode
      dim nErrorCode() as long
      

  6.   

    //大家都解决了最简单的问题,关键问题怎么不动呢?
    关键是const  char  *sValidTime,  int  *nErrorCode等问题,而且还要解决如何引用并赋值的问题,大家继续啊!~高手大侠请不要手下留情哦!该出手时就出手!
    呵呵const  char  *sValidTime
    可以声明为ByVal sValidTime  As Long(注意要用strptr取得字串的地址,并传递)int  *nErrorCode同理
    可以声明为ByVal nErrorCode As Long(用varptr取得地址并传递)总而言之,指针都声明为long(可用strptr,varptr,objptr获得地址)
      

  7.   

    如何引用该函数呢?比如函数int AA(const char *n1,const int *n2) 
    定义为:dim AA(n1() as string,n2() as long) as long
    如何引用该函数呢?
      

  8.   

    //比如函数int AA(const char *n1,const int *n2) Private Declare Function AA Lib "你的dll文件名" (ByVal n1 As Long,ByVal n2 As Long) As Long调用时,先用strptr获得n1对应子串的地址,再用varptr获得n2对应数值的地址,然后传递这两个地址
      

  9.   

    谢谢rainstormmaster(暴风雨 v2.0)
      

  10.   

    还有个问题,n1定义长度为char(11),如何定义和引用?还有就是如何获得自定义type的地址?谢谢
      

  11.   

    那还不如直接用 as any呢。
    Private Declare Function AA Lib "你的dll文件名" (n1 As Any,n2 As Any) As Long
    调用的时候:
    ret=AA(n1(0),n2(0))
    这不就是指针传递?
      

  12.   

    是不是__stdcall协议的?
    SMGPAPI_EXPORTS是哪种协议的宏?VB只能调用__stdcall协议的函数