这是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);
如下一个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);
{
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
{
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
关键是const char *sValidTime, int *nErrorCode等问题,而且还要解决如何引用并赋值的问题,大家继续啊!~高手大侠请不要手下留情哦!该出手时就出手!
dim sValidTime() as stringint *nErrorCode
dim nErrorCode() as long
关键是const char *sValidTime, int *nErrorCode等问题,而且还要解决如何引用并赋值的问题,大家继续啊!~高手大侠请不要手下留情哦!该出手时就出手!
呵呵const char *sValidTime
可以声明为ByVal sValidTime As Long(注意要用strptr取得字串的地址,并传递)int *nErrorCode同理
可以声明为ByVal nErrorCode As Long(用varptr取得地址并传递)总而言之,指针都声明为long(可用strptr,varptr,objptr获得地址)
定义为:dim AA(n1() as string,n2() as long) as long
如何引用该函数呢?
Private Declare Function AA Lib "你的dll文件名" (n1 As Any,n2 As Any) As Long
调用的时候:
ret=AA(n1(0),n2(0))
这不就是指针传递?
SMGPAPI_EXPORTS是哪种协议的宏?VB只能调用__stdcall协议的函数