In this method first running A_index increases normally,but A_index doesn't increase(alwayse 1) since Init method second running.
Code: Select all
Init(server,brokerid,accountid,pwd){
......
this.stat:=0
while(this.stat<1){
Sleep,1000
OutputDebug,% A_Index
if(A_Index>=5)
return false
}
return true
}
Code: Select all
this.stat:=0
myvar:=0
while(this.stat<1){
Sleep,1000
myvar++
OutputDebug,% myvar
if(myvar>=5)
return false
}
return true
whole script:
Code: Select all
oMD:=new MDclass()
oMD.Init("tcp://8.8.8.8:51213","1000","00000001","123456")
oMD.Init("tcp://8.8.8.8:51213","1000","00000001","123456")
oMD.Init("tcp://8.8.8.8:51213","1000","00000001","123456")
Sleep,1000000
return
class MDclass{
static stat:=0
static hModule,pMd,pMsgQueue
,CTP_CreateMsgQueue,CTP_ReleaseMsgQueue,CTP_StartMsgQueue,CTP_StopMsgQueue,CTP_ClearMsgQueue,CTP_RegOnConnect
,MD_CreateMdApi,MD_ReleaseMdApi,MD_Connect,MD_Disconnect,MD_RegMsgQueue2MdApi
__New(){
this.hModule := DllCall("LoadLibrary", "Str", "C2CTP.dll", "Ptr")
this.CTP_CreateMsgQueue :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_CreateMsgQueue@0")
this.CTP_ReleaseMsgQueue :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_ReleaseMsgQueue@4")
this.CTP_ClearMsgQueue :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_ClearMsgQueue@4")
this.CTP_StartMsgQueue :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_StartMsgQueue@4")
this.CTP_StopMsgQueue :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_StopMsgQueue@4")
this.CTP_RegOnConnect :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_CTP_RegOnConnect@8")
this.MD_CreateMdApi :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_MD_CreateMdApi@0")
this.MD_ReleaseMdApi :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_MD_ReleaseMdApi@4")
this.MD_Connect :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_MD_Connect@24")
this.MD_RegMsgQueue2MdApi :=DllCall("GetProcAddress",Ptr,this.hModule,aStr,"_MD_RegMsgQueue2MdApi@8")
this.pMsgQueue:=DllCall(this.CTP_CreateMsgQueue)
this.pMd:=DllCall(this.MD_CreateMdApi)
DllCall(this.CTP_RegOnConnect,Ptr,this.pMsgQueue,Ptr,RegisterCallback("MD_OnConnect", "", "", &this))
}
__Delete(){
DllCall(this.MD_ReleaseMdApi,Ptr,this.pMd)
DllCall(this.CTP_StopMsgQueue,Ptr,this.pMsgQueue)
DllCall(this.CTP_ReleaseMsgQueue,Ptr,this.pMsgQueue)
DllCall("FreeLibrary", "Ptr", this.hModule)
}
Init(server,brokerid,accountid,pwd){
static THOST_TERT_RESTART:=0,THOST_TERT_RESUME:=1,THOST_TERT_QUICK:=2
DllCall(this.CTP_ClearMsgQueue,Ptr,this.pMsgQueue)
DllCall(this.MD_RegMsgQueue2MdApi,Ptr,this.pMd,Ptr,this.pMsgQueue)
DllCall(this.MD_Connect,Ptr,this.pMd,Astr,"account\\" . accountid . "\\",Astr,server,Astr,brokerid,Astr,accountid,Astr,pwd,Int,THOST_TERT_QUICK,Astr,"",Astr,"")
DllCall(this.CTP_StartMsgQueue,Ptr,this.pMsgQueue)
this.stat:=0
while(this.stat<1){
Sleep,1000
OutputDebug,% A_Index ;it doesn't increase since second run
if(A_Index>=5)
return false
}
return true
}
}
MD_OnConnect(pApi,pRspUserLogin,step){
Critical,60
OutputDebug,% "connecting " step
if(step>=8){
Object(A_EventInfo).stat:=1
}
}