ynbIpb Posted February 16, 2011 Posted February 16, 2011 (edited) Please help convert a small example to Autoit.This is an example of interaction with the component: wodXMPP ActiveX componentNeed connect to the server, send and receive messages.Help please. I can not deal with COM objects.Thank you!In Attach an archive with everything you need: the project on VB 5, Component and the test account.Simple_example_VB_5.rar Edited February 16, 2011 by ynbIpb
ynbIpb Posted February 16, 2011 Author Posted February 16, 2011 Here are my achievements. I can connect to the server, send messages to the user. The main problem: How do I receive messages? expandcollapse popup#NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> OnAutoItExitRegister( "_Jdisconnect" ) $sWodXMPP_dll = @SystemDir & "\wodXMPP.dll" $sSettings_ini = @ScriptDir & "\settings.ini" If FileExists ($sWodXMPP_dll) = 0 Then FileCopy (@ScriptDir & "\wodXMPP.dll", $sWodXMPP_dll, 1) ; copy to system folder RunWait(@SystemDir & '\regsvr32.exe /s ' & $sWodXMPP_dll) ; register a component in the system EndIf $xmpp = ObjCreate("WeOnlyDo.wodXMPPCom.1") $Form1 = GUICreate("Simple Example wodXMPP ActiveX", 528, 410) $Label1 = GUICtrlCreateLabel("Jabber ID:", 8, 8, 53, 17) $Label2 = GUICtrlCreateLabel("Password:", 8, 32, 53, 17) $Input1 = GUICtrlCreateInput("", 65, 5, 215, 21) ; jabber ID $Input2 = GUICtrlCreateInput("", 65, 30, 215, 21) ; password $List1 = GUICtrlCreateList("", 288, 5, 233, 357) $Checkbox1 = GUICtrlCreateCheckbox("Register as new user", 8, 60, 177, 17) $Button1 = GUICtrlCreateButton("Go online", 8, 90, 132, 35) $Button2 = GUICtrlCreateButton("Offline", 148, 90, 132, 35) GUICtrlSetState ($Button2, $GUI_DISABLE) $Label3 = GUICtrlCreateLabel("Send message to:", 8, 327, 89, 17) $Input3 = GUICtrlCreateInput("", 104, 324, 177, 21) $Edit1 = GUICtrlCreateEdit("", 8, 348, 218, 50, BitOR ($ES_MULTILINE, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_WANTRETURN)) $Button3 = GUICtrlCreateButton("Send", 230, 348, 50, 50) GUICtrlSetState ($Button3, $GUI_DISABLE) $Label4 = GUICtrlCreateLabel("", 288, 368, 233, 35, $SS_CENTER) If FileExists ($sSettings_ini) Then GUICtrlSetData ($Input1, IniRead ($sSettings_ini, "general", "jid", "")) GUICtrlSetData ($Input2, IniRead ($sSettings_ini, "general", "pass", "")) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Connect_to_server() Case $Button2 _Disconnect_from_server() Case $Button3 _send_message () EndSwitch WEnd Func _Connect_to_server() $sJid = GUICtrlRead ($Input1) $sPass = GUICtrlRead ($Input2) If $sJid = "" Or $sPass = "" Then GUICtrlSetData ($Label4, "Error! Please enter your login and password") Return EndIf GUICtrlSetData ($Label4, "Connecting...") $xmpp.Security = 0 $xmpp.Authentication = 0 $xmpp.Login = $sJid $xmpp.Password = $sPass $conn_timer_begin = TimerInit() $iStatus = $xmpp.State If $iStatus = 0 Then $xmpp.Connect While $iStatus <> 5 sleep (200) $iStatus = $xmpp.State $conn_timer_diff = TimerDiff($conn_timer_begin) If $conn_timer_diff >= 20000 And $iStatus = 0 Then GUICtrlSetData ($Label4, "Error! Not Connected") Return EndIf WEnd EndIf GUICtrlSetData ($Label4, "Online!") GUICtrlSetState ($Button1, $GUI_DISABLE) GUICtrlSetState ($Button2, $GUI_ENABLE) GUICtrlSetState ($Button3, $GUI_ENABLE) EndFunc Func _send_message () $sMessageText = GUICtrlRead ($Edit1) $sRecipient = GUICtrlRead ($Input3) If $sMessageText = "" or $sRecipient = "" Then GUICtrlSetData ($Label4, "Error! Nothing to send or no the recipient.") Return EndIf $xmpp.SendText ($sRecipient, $sMessageText) GUICtrlSetData ($Edit1, "") EndFunc Func _Disconnect_from_server() $xmpp.Disconnect GUICtrlSetData ($Label4, "Offline!") GUICtrlSetState ($Button2, $GUI_DISABLE) GUICtrlSetState ($Button3, $GUI_DISABLE) GUICtrlSetState ($Button1, $GUI_ENABLE) EndFunc Func _Jdisconnect () $xmpp.Disconnect EndFunc
enaiman Posted February 16, 2011 Posted February 16, 2011 Look for a similar function to "SendText". I'm sure it has a "receiveText" too or something similar. You might need to use AdLib to check every 250+ ms if there is anything to be received. Check the documentation properly because there is something in there; the guys from WoD are doing a good job. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
trancexx Posted February 16, 2011 Posted February 16, 2011 (edited) The secret is ObjEvent function. You should learn o use it o be able to get the most out of this. Another good thing is AutoItObject.au3 (search the forums). It makes registering redundant. That means the user doesn't have to be admin to be able to use your app. Example would (or could) be: expandcollapse popup#NoTrayIcon #include <EditConstants.au3> #include <GUIConstantsEx.au3> #AutoIt3Wrapper_UseX64=n #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include "AutoItObject.au3" _AutoItObject_Startup() ; Error monitoring Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ConsoleWrite("! COM Error ! Number: 0x" & Hex($oError.number, 8) & " ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF) Return EndFunc ;==>_ErrFunc OnAutoItExitRegister( "_Jdisconnect" ) $sSettings_ini = @ScriptDir & "\settings.ini" ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $sWodXMPP_dll = @ScriptDir & "\wodXMPP.dll" $sCLSID = "{19DCD07D-C515-45FD-A008-AB0D90743EDE}" $sIID = "{D79294AB-FB41-43DF-A625-885D4E2E8AAC}" ;~ $xmpp = ObjCreate("WeOnlyDo.wodXMPPCom.1") $xmpp = _AutoItObject_ObjCreateEx($sWodXMPP_dll, $sCLSID, $sIID) Global $oEvent = ObjEvent($xmpp, "wodXMPP1_", "_IwodXMPPComEvents") ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX $Form1 = GUICreate("Simple Example wodXMPP ActiveX", 528, 410) $Label1 = GUICtrlCreateLabel("Jabber ID:", 8, 8, 53, 17) $Label2 = GUICtrlCreateLabel("Password:", 8, 32, 53, 17) $Input1 = GUICtrlCreateInput("", 65, 5, 215, 21) ; jabber ID $Input2 = GUICtrlCreateInput("", 65, 30, 215, 21) ; password $List1 = GUICtrlCreateList("", 288, 5, 233, 357) $Checkbox1 = GUICtrlCreateCheckbox("Register as new user", 8, 60, 177, 17) $Button1 = GUICtrlCreateButton("Go online", 8, 90, 132, 35) $Button2 = GUICtrlCreateButton("Offline", 148, 90, 132, 35) GUICtrlSetState ($Button2, $GUI_DISABLE) $Label3 = GUICtrlCreateLabel("Send message to:", 8, 327, 89, 17) $Input3 = GUICtrlCreateInput("", 104, 324, 177, 21) $Edit1 = GUICtrlCreateEdit("", 8, 348, 218, 50, BitOR ($ES_MULTILINE, $ES_AUTOVSCROLL, $ES_MULTILINE, $ES_WANTRETURN)) $Button3 = GUICtrlCreateButton("Send", 230, 348, 50, 50) GUICtrlSetState ($Button3, $GUI_DISABLE) $Label4 = GUICtrlCreateLabel("", 288, 368, 233, 35, $SS_CENTER) If FileExists ($sSettings_ini) Then GUICtrlSetData ($Input1, IniRead ($sSettings_ini, "general", "jid", "")) GUICtrlSetData ($Input2, IniRead ($sSettings_ini, "general", "pass", "")) EndIf GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Connect_to_server() Case $Button2 _Disconnect_from_server() Case $Button3 _send_message () EndSwitch WEnd Func _Connect_to_server() $sJid = GUICtrlRead ($Input1) $sPass = GUICtrlRead ($Input2) If $sJid = "" Or $sPass = "" Then GUICtrlSetData ($Label4, "Error! Please enter your login and password") Return EndIf GUICtrlSetData ($Label4, "Connecting...") $xmpp.Security = 0 $xmpp.Authentication = 0 $xmpp.Login = $sJid $xmpp.Password = $sPass $conn_timer_begin = TimerInit() $iStatus = $xmpp.State If $iStatus = 0 Then $xmpp.Connect While $iStatus <> 5 sleep (200) $iStatus = $xmpp.State $conn_timer_diff = TimerDiff($conn_timer_begin) If $conn_timer_diff >= 20000 And $iStatus = 0 Then GUICtrlSetData ($Label4, "Error! Not Connected") Return EndIf WEnd EndIf GUICtrlSetData ($Label4, "Online!") GUICtrlSetState ($Button1, $GUI_DISABLE) GUICtrlSetState ($Button2, $GUI_ENABLE) GUICtrlSetState ($Button3, $GUI_ENABLE) EndFunc Func _send_message () $sMessageText = GUICtrlRead ($Edit1) $sRecipient = GUICtrlRead ($Input3) If $sMessageText = "" or $sRecipient = "" Then GUICtrlSetData ($Label4, "Error! Nothing to send or no the recipient.") Return EndIf $xmpp.SendText ($sRecipient, $sMessageText) GUICtrlSetData ($Edit1, "") EndFunc Func _Disconnect_from_server() $xmpp.Disconnect GUICtrlSetData ($Label4, "Offline!") GUICtrlSetState ($Button2, $GUI_DISABLE) GUICtrlSetState ($Button3, $GUI_DISABLE) GUICtrlSetState ($Button1, $GUI_ENABLE) EndFunc Func _Jdisconnect () $xmpp.Disconnect EndFunc ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Func wodXMPP1_Connected() ConsoleWrite(">Fired when wodXMPP connects. So, it should be connected now." & @CRLF) EndFunc Func wodXMPP1_Disconnected($iErrorCode, $sErrorText) ConsoleWrite("-Fired when wodXMPP disconnected -> ErrorCode = " & $iErrorCode & ", ErrorText = " & $sErrorText & @CRLF) EndFunc Func wodXMPP1_IncomingMessage($oContact, $oChatRoom, $oMessage) ConsoleWrite("+>Fired when new message is received -> Message from " & $oContact.Nick & ":" & @TAB & $oMessage.Text & @CRLF) EndFunc ;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX Third good thing that you could use is TLBViewer.au3 (again search for it). That's how I expanded your script. edit: untested of course. And using wodXMPP.dll from script's dir. Edited February 16, 2011 by trancexx ♡♡♡ . eMyvnE
ynbIpb Posted February 17, 2011 Author Posted February 17, 2011 (edited) Thank you for your answers. Component developers are good people, but they do not work with AutoIt and can not make an example.Yes, the problem is Object Event - I do not understand how to work with him. And with the new "AutoItObject.au3" I am even more confused.trancexx, in your example, works only: wodXMPP1_Connected () event. Please show a working example of the incoming message without "AutoItObject.au3".I read the documentation, but I do not understand how it works.Here is the base of all examples.Please help. Edited February 17, 2011 by ynbIpb
ynbIpb Posted February 17, 2011 Author Posted February 17, 2011 And others can see it? Or do you need more time?
enaiman Posted February 17, 2011 Posted February 17, 2011 The AutoIT Object is there just to intercept the errors you might get during the script execution - you should be really grateful to trancexx for mentioning that because otherwise whenever you had an error related to WoD object your script would just exit without giving you a clue why it did so. You should keep that right there in the script because it does not interfere. Trancexx example is exactly what you need and it should work. Looking at the documentation link you provided, I can notice that the specify a ChatRoom object but it doesn't show in the function's parameters: Private Sub object_IncomingMessage(Contact, Message) ChatRoom parameter is set to Nothing if this is direct message from the contact. If ChatRoom is set, it contains reference to the chat room from where is message coming. What I would suggest you to try is to replace this line: wodXMPP1_IncomingMessage($oContact, $oChatRoom, $oMessage) with wodXMPP1_IncomingMessage($oContact, $oMessage) and see what happens. "Events" are fired everytime something specific happens. Like "connect" - that actually tells you "I am connected", so if you build such a function, it will notify you when that happens; same with IncomingMessage, this one will tell you that you have an incoming message, the message text and from whom it is. A piece of advice, before saying that a solution "doesn't work" be sure to post whatever error info you can, error message, behaviour, console output ... whatever helps. We are not mind-readers and we are not sitting in front of your computer to see what happens and definitely we are not installing the software (in your case the WoD software) just to debug your script. Failing to give error info will result in your problem not being solved because nobody has such spare time and goodwill and patience for babysitting. SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :)
ynbIpb Posted February 18, 2011 Author Posted February 18, 2011 No errors. In the console only:>Fired when wodXMPP connects. So, it should be connected now.I do not understand how did these variables: $oContact, $oChatRoom, $oMessageFor them need to create objects?
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now