Ratonal中使用dll文件的例子
在实际应用中,由于Rational脚本编写的限制,或者实现起来比较麻烦,我们可以通过其他工具编写dll来实现功能,然后在脚本中调用,请看下面例子!首先将dll文件拷贝到:TestDatastore\DefaultTestscrīptDatastore\TMS_scrīpts\externC文件夹下面
//先取好友列表组
//声明外部动态链接库函数
external_C int func stoi(str,icount)
string str;
int icount;
{}
#include <VU.h>
{
{//int file1;
string lxj;
string len;
string friend;
int bool=0;
int i;
string chatId;
string friendId;
//int count=10000;
// int count1;
int nlogin;
shared loginNum;
shared getFriendMun;
}
//count1=count;
DP1 = datapool_open ("RespId");
datapool_fetch(DP1);
chatId = datapool_value(DP1, "chatId");
friendId= datapool_value(DP1, "friendId");
set Think_avg = 5;
qqchat = sock_connect("xgaa001", "192.168.0.89:8101");
//{ INFO SERVER "wudp.gwsoftd.ccdx"="192.168.0.95"; } /*1*/
set Server_connection = qqchat;
//发登陆包
nlogin=0;
while (nlogin==0){
sock_send
"`fdfd0000003900000000000000000000000000010001000000000000010020"
+friendId+"01010003000c30003000300030003000300000084700410031003600`";
delay(1000);
nlogin=sock_isinput();
}
sock_nrecv ["login001"] 2;
sock_nrecv ["login002"] 4;
lxj=mixed2hexstring(_response);
len = substr(lxj,2,8); //需要的信息后续报长度是1到8位,截取时前面要加上字符串的飘号
log_msg ("the long of the packag:" + len);
ilen = stoi(len,8);
log_msg ("the long of the packag:"+itoa(ilen));
sock_nrecv["login003"] ilen;//登陆返回的消息全部收完
//if (substr(_response,46,2)=="18") //需要的信息命令字是45、46位,截取时前面要加上字符串的飘号
// count=count-1;
delay(1000);
log_msg(itoa(sock_isinput()));
loginNum++;
delay(30000);
//delay(30000);
//datapool_close (DP1);
/*//接受好友登陆消息和对聊消息
nlogin=sock_isinput();//一直判断当前是否有消息到来
while (nlogin!=0) {
sock_nrecv ["changestatus001"] 2;
sock_nrecv ["changestatus002"] 4;
lxj=mixed2hexstring(_response);
len = substr(lxj,2,8);
ilen = stoi(len,8);
sock_nrecv["changestatus003"] ilen;
if (substr(_response,46,2)=="18") //发现有聊天消息,则统计次数少1,共聊天 count次数
count=count-1;
delay(1000);
nlogin=sock_isinput();
} */
//delay(30000);
wait(&loginNum, 100, 100);
//取得好友列表
nlogin=sock_isinput();
sock_nrecv["log003"] nlogin;
nlogin=sock_isinput();
log_msg("aaaaaaa"+ itoa(sock_isinput()));
while (nlogin==0){
sock_send
"`fdfd0000001d000000000000000000000000000100020000000000000f0004"+friendId+"`";
delay(1000);
nlogin=sock_isinput();
}
getFriendMun++;
sock_nrecv ["getFriend001"] 2;
sock_nrecv ["getFriend002"] 4; //接收的“后续包长度”, 协议列表中“消息包长度”=“业务体长度”
lxj=mixed2hexstring(_response);
len = substr(lxj,2,8);
ilen = stoi(len,8);
sock_nrecv["getFriend003"] ilen; //从“地址”开始接收
lxj=mixed2hexstring(_response);
friend=substr(lxj,76,8);//好友的通道ID
//发送对聊消息
//发送聊天消息
//delay(30000);
wait(&getFriendMun, 100, 100);
/*if (count<count1)
{sock_send
"`fdfd00000031c0a800`Y \t`"+friend+"00000001000a000000000000180018"+friendId+"00"
"12340036003500340033003200310030003000`";
log_msg("???");
} */
for (i=0;i<10000;i++){
sock_send
"`fdfd00000031c0a800`Y \t`"+friend+"00000001000a000000000000180018"+friendId+"00"
"12340036003500340033003200310030003000`";
delay(50);
nlogin=sock_isinput();
sock_nrecv["log003"] nlogin;
//得到聊天回应消息
//加:若聊天5次则发在线查询包,并收完。保证在线!!!
}
}
DATAPOOL_CONFIG "RespId"DP_NOWRAP DP_SEQUENTIAL DP_SHARED
{
INCLUDE, "chatId", "string", "000480d9";
INCLUDE, "friendId", "string", "0004810b";
}
回复 #1 oftime999 的帖子
厉害1
页:
[1]