Jump to content

Recommended Posts

Posted

My objective was to translate to VBScript into an au3 file so I can code in autoit. I have most of it done however There seems to be certain COM events that autoit does not seem to catch. Mostly the session_SessionStatusChanged and session_SessionStatusLoginError that do not seem to work.

When I run it in VBScript it works fine.

Any ideas on what I might be doing wrong? I also attached the VBS file I was copying from.

 

;~ 'SessionStatusCode enum
Const $SessionStatusCode_Disconnected = 0
Const $SessionStatusCode_Connecting = 1
Const $SessionStatusCode_TradingSessionRequested = 2
Const $SessionStatusCode_Connected = 3
Const $SessionStatusCode_Disconnecting = 5
Const $SessionStatusCode_SessionLost = 6
Const $SessionStatusCode_PriceSessionReconnecting = 7
Const $SessionStatusCode_Unknown = 8

$username = ""
$password = ""

If $username = "" Or $password = "" Then
    MsgBox(16, "Error", "Please provide username and password to the appropriate variables")
    Exit
EndIf

$LastStatus = ""
$LastError = ""

MsgBox(0, "", "Login and logout")

$core = ObjCreate("fxcore2.com.Transport")

$session = $core.createSession()
$Event = ObjEvent($session, "session_")

MsgBox(0, "", "Log in...")
$session.login($username, $password, "http://www.fxcorporate.com/Hosts.jsp", "Demo")

While $LastStatus <> $SessionStatusCode_Connected And $LastError = ""
    Sleep(50)
WEnd

MsgBox(0, "", "Log out...")
$session.logout
While $LastStatus <> $SessionStatusCode_Disconnected
    Sleep(50)
WEnd

MsgBox(0, "", "Session status:" & GetStatusName($LastStatus))

$session = ""

MsgBox(0, "", "Done !")

Func session_SessionStatusChanged($status)
    MsgBox(0, "", "Status changed: " & GetStatusName($status))
    $LastStatus = $status
EndFunc   ;==>session_SessionStatusChanged

Func session_SessionStatusLoginError($err)
    MsgBox(16, "Error", "Error occured: " & $err)
    $LastError = "err"
EndFunc   ;==>session_SessionStatusLoginError

Func GetStatusName($status)
    Switch $status
        Case $SessionStatusCode_Connected
            $varGetStatusName = "connected"
        Case $SessionStatusCode_Disconnected
            $varGetStatusName = "disconnected"
        Case $SessionStatusCode_Connecting
            $varGetStatusName = "connecting"
        Case $SessionStatusCode_TradingSessionRequested
            $varGetStatusName = "trading session requested"
        Case $SessionStatusCode_Disconnecting
            $varGetStatusName = "disconnecting"
        Case $SessionStatusCode_SessionLost
            $varGetStatusName = "session lost"
        Case $SessionStatusCode_PriceSessionReconnecting
            $varGetStatusName = "price session reconnecting"
        Case $SessionStatusCode_Unknown
            $varGetStatusName = "unknown"
        Case Else
            $varGetStatusName = $status
    EndSwitch
    Return $varGetStatusName
EndFunc   ;==>GetStatusName

 

login.vbs

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Posted (edited)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Did you run this:

"c:\Program Files (x86)\Candleworks\ForexConnectAPI\bin-com\registerCom.bat" 

 

as ADMIN ? (you must use RightMouseButton and choose "Run as Administrator"

??

 

 

 

BTW:

this forum section is "Support for the ActiveX and DLL versions of AutoIt.
This mean how to use AutoIt inside C# or C++ or in any other dev.env.

Not for "Any third party ActiveX component which can be used in AutoIt"

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 6/2/2015 at 5:28 PM, mLipok said:

Hi.

I see you was asking here:

http://www.dailyfx.com/forex_forum/forexconnect/649823-trouble-com-events.html

 

​HAHA yeah you found it. :P

 

  On 6/2/2015 at 6:46 PM, mLipok said:

Did you run this:

"c:\Program Files (x86)\Candleworks\ForexConnectAPI\bin-com\registerCom.bat" 

as ADMIN ? (you must use RightMouseButton and choose "Run as Administrator"

??

BTW:

this forum section is "Support for the ActiveX and DLL versions of AutoIt.
This mean how to use AutoIt inside C# or C++ or in any other dev.env.

Not for "Any third party ActiveX component which can be used in AutoIt"

 

​Well I will try running that bat file as admin when I get home and let you know.

Next time I will post this under general support.

Out of curiosity, were you able to catch the events coming out of those 2 functions? I find it strange that the VBS file works perfectly fine but not with autoit. I tried 64 and 32 mode.

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Posted
;~ 'SessionStatusCode enum
Const $SessionStatusCode_Disconnected = 0
Const $SessionStatusCode_Connecting = 1
Const $SessionStatusCode_TradingSessionRequested = 2
Const $SessionStatusCode_Connected = 3
Const $SessionStatusCode_Disconnecting = 5
Const $SessionStatusCode_SessionLost = 6
Const $SessionStatusCode_PriceSessionReconnecting = 7
Const $SessionStatusCode_Unknown = 8

$username = ""
$password = ""


#cs
If $username = "" Or $password = "" Then
    MsgBox(16, "Error", "Please provide username and password to the appropriate variables")
    Exit
EndIf

#CE

$LastStatus = ""
$LastError = ""
Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

MsgBox(0, "", "Login and logout")


$core = ObjCreate("fxcore2.com.Transport")

$session = $core.createSession()
$Event = ObjEvent($session, "session_")

MsgBox(0, "", "Log in...")
$session.login($username, $password, "http://www.fxcorporate.com/Hosts.jsp", "Demo")

While $LastStatus <> $SessionStatusCode_Connected And $LastError = ""
    Sleep(50)
WEnd

MsgBox(0, "", "Log out...")
$session.logout
While $LastStatus <> $SessionStatusCode_Disconnected
    Sleep(50)
WEnd

MsgBox(0, "", "Session status:" & GetStatusName($LastStatus))

$session = ""

MsgBox(0, "", "Done !")

Func session_SessionStatusChanged($status)
    MsgBox(0, "", "Status changed: " & GetStatusName($status))
    $LastStatus = $status
EndFunc   ;==>session_SessionStatusChanged

Func session_SessionStatusLoginError($err)
    MsgBox(16, "Error", "Error occured: " & $err)
    $LastError = "err"
EndFunc   ;==>session_SessionStatusLoginError

Func session_LoginFailed($err)
    MsgBox(16, "Error", "Error occured: " & $err)
    $LastError = "err"
EndFunc   ;==>session_SessionStatusLoginError

Func GetStatusName($status)
    Switch $status
        Case $SessionStatusCode_Connected
            $varGetStatusName = "connected"
        Case $SessionStatusCode_Disconnected
            $varGetStatusName = "disconnected"
        Case $SessionStatusCode_Connecting
            $varGetStatusName = "connecting"
        Case $SessionStatusCode_TradingSessionRequested
            $varGetStatusName = "trading session requested"
        Case $SessionStatusCode_Disconnecting
            $varGetStatusName = "disconnecting"
        Case $SessionStatusCode_SessionLost
            $varGetStatusName = "session lost"
        Case $SessionStatusCode_PriceSessionReconnecting
            $varGetStatusName = "price session reconnecting"
        Case $SessionStatusCode_Unknown
            $varGetStatusName = "unknown"
        Case Else
            $varGetStatusName = $status
    EndSwitch
    Return $varGetStatusName
EndFunc   ;==>GetStatusName

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc
  Quote

.............................................................

>Running:(3.3.10.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\user\Downloads\fxcore2.com.Transport.au3"    
--> Press Ctrl+F11 to Restart or Ctrl+Break -or- F11 to Stop
fxcore2.com.Transport.au3 (34) : ==> COM Error intercepted !
    err.number is:         0x80028017
    err.windescription:    Nazwa pola nie jest zdefiniowana w rekordzie.

    err.description is:     
    err.source is:         
    err.helpfile is:     
    err.helpcontext is:     
    err.lastdllerror is:     0
    err.scriptline is:     34
    err.retcode is:     0x00000000

.............................................................

English translation: Field name not defined in the record.

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

So I tried running the registerCom.bat as admin like you said (which I am pretty sure is auto run during the install) but no success. I also added #RequireAdmin at the top of my script which I should have tried in the first place but still nothing. I am still scratching my head, please let me know if you find something.

 

  Quote

English translation: Field name not defined in the record.

To solve this problem you need to install the newest API and the newest COM API which can be found here. http://fxcodebase.com/wiki/index.php/Download

I Installed all 4 of these to cover my bases. Which allows me to create the objects but not to catch the events the same way the VBS script does.

Latest Stable Release (1.3.0)

http://www.fxcorporate.com/ForexConnect-2013-1.3.0/ForexConnectAPI-1.3.0-win32.exe

http://www.fxcorporate.com/ForexConnect-2013-1.3.0/ForexConnectAPI-1.3.0-win64.exe

http://fxcodebase.com/bin/forexconnect/1.3.0/ForexConnectAPI-1.3.0-win32-COM.exe

http://fxcodebase.com/bin/forexconnect/1.3.0/ForexConnectAPI-1.3.0-win64-COM.exe

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Posted
  On 6/3/2015 at 3:27 AM, trancexx said:

AutoIt does some additional checks to ensure the default sink is correctly implemented.

Quick look suggests calling it like this should work:

ObjEvent($session, "session_", "ISessionCallback")

 

First off, I have seen your contributions to Autoit and I am honored by you presence.

That's did it, I KNEW there should have been something I needed to add there! Especially as indicated by the ObjEvent page in the help file. How did you find what interface name needed to be used? I was searching around in the OLEviewer.exe and could not find what I was looking for.

No problem can withstand the assault of sustained thinking.Voltaire

_Array2HTMLTable()_IEClassNameGetCollection()_IEquerySelectorAll()

Posted
  On 6/3/2015 at 4:02 AM, uncommon said:

First off, I have seen your contributions to Autoit and I am honored by you presence.

That's did it, I KNEW there should have been something I needed to add there! Especially as indicated by the ObjEvent page in the help file. How did you find what interface name needed to be used? I was searching around in the OLEviewer.exe and could not find what I was looking for.

​You have to examine typelib. Typelib is usually stored as resource of some dll (ocx, whatever), or found as standalone file with .tlb extension.
For example to find out where are the definitions, you would do something like this:

$core = ObjCreate("fxcore2.com.Transport")

ConsoleWrite("TypeLib is at " & ObjName($core, 4) & @CRLF)

Then you would load it to OLEviewer.exe and see what's there.

I wrote one Typelib viewer in AutoIt 100 years ago that you can use to explore TLBs, it's right here https://www.autoitscript.com/forum/topic/116735-typelib-viewer/. Just drop the file with path printed above and you will get all the info you need about all objects from forexcon, including ISessionCallback name and definition.

♡♡♡

.

eMyvnE

Posted

@trancexx

Many thanks for the clarification.
Again I broadened a bit of my knowledge.

 

mLipok

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...