Sign in to follow this  
Followers 0
pippi

Question about COM interfaces

9 posts in this topic

Is it possible in AutoIt to implement an interface from a type library, whose methods would be implemented in AutoIt- functions? In VB the code would look something like this:

Implements IMbtQuotesNotify

Public Sub IMbtQuotesNotify_OnQuoteData(pQuote As MBTQUOTELib.QUOTERECORD)

.

.

End Sub

I am currently learning how to use COM/AutoIt, and i am not haveing problems with normal automation and events, however i have no idea how to go on about the above. Hope someone can help.

Regards,

Andy

Share this post


Link to post
Share on other sites



Do you know what the com object is called?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Yes, i have the complete documentation of the COM components.

Edited by pippi

Share this post


Link to post
Share on other sites

Ok, heres the next step.

TELL us the name.

Share this post


Link to post
Share on other sites

OK, sorry, i am rather new to COM, i have a working VB script that i am trying to translate to autoit, and 90% is already working. Its rather long, so i will cut it down and show you, maybe someone can help then. Ill post it in a bit.

Share this post


Link to post
Share on other sites

Ok, here is an VB makro that i use in excel. It logs into a trading server and continuously displays real time prices for the Google stock.

The broker i use provides a SDK of COM-compatible components, i have written some small tools in excel so far. Now i am trying some things with AutoIt. So far pretty much works (login, events, reading account balances and so on), except when it comes to IMbtQuotesNotify-interface. The IMbtQuotesNotify_OnQuoteData method in below VB example isnt really an event, is it? How would i do it in AutoIt?

Option Explicit
Implements IMbtQuotesNotify                  ' Client should implement this interface in order to receive realtime quote callbacks

Public WithEvents moComMgr As MbtComMgr      ' this is the toplevel object in this SDK framework
Public WithEvents moQuotes As MbtQuotes      ' object that provides realtime quotes
Public moAcct As MbtAccount                  ' the account object
Public mbGotLogin As Boolean

Public Sub cmdOK_Click()                        ' called when clicked on the "login" button"
   Set moComMgr = New MbtComMgr              ' retrieving the main application class object
   Set moQuotes = moComMgr.Quotes              ' retrieving the quotes object
   mbGotLogin = moComMgr.DoLogin(9, "username", "password", "")   ' login to trading servers
End Sub

Private Sub cmdAdvise_Click()                  ' called when clicked on the "advise button"
   moQuotes.UnadviseAll frmLogin                ' delete current interestlist
   moQuotes.AdviseSymbol frmLogin, "GOOG", 1   ' Adds Google stocksymbol to interest list and registers callback interface to receive its quotes
End Sub

Private Sub cmdUnadvise_Click()              ' called when clicked on the "unadvise button"
   moQuotes.UnadviseAll Me                    ' removes interest for all quotesymbols that were registered to the given callback interface
End Sub

Public Sub IMbtQuotesNotify_OnQuoteData(pQuote As MBTQUOTELib.QUOTERECORD) ' direct event called when new quotedata has arrived for an advised quotesymbol
   Dim dBid As Double
   Dim dAsk As Double
   dBid = pQuote.dBid
   dAsk = pQuote.dAsk
   Sheet1.Cells(2, "B").Value = dBid            ' write newly arrived quote to cell
   Sheet1.Cells(2, "C").Value = dAsk            ' write newly arrived quote to cell
End Sub

Public Sub IMbtQuotesNotify_OnLevel2Data(pRec As MBTQUOTELib.LEVEL2RECORD)    ' method must be defind for IMbtQuotesNotify
End Sub

Public Sub IMbtQuotesNotify_OnOptionsData(pRec As MBTQUOTELib.OPTIONSRECORD)    ' method must be defind for IMbtQuotesNotify
End Sub

Public Sub IMbtQuotesNotify_OnTSData(pRec As MBTQUOTELib.TSRECORD)            ' method must be defind for IMbtQuotesNotify
End Sub

Private Sub UserForm_Initialize()              ' start displaying GUI
End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)        ' stuff to do when closing GUI
   moQuotes.UnadviseAll Me
   Set moQuotes = Nothing
   Set moComMgr = Nothing
End Sub

Any help is appreciated,

regards,

Andy

Share this post


Link to post
Share on other sites

All I needed was this:

MbtComMgr

EDIT::

No, Thats not it. Can we have the name?


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

All I needed was this:

MbtComMgr

EDIT::

No, Thats not it. Can we have the name?

Sorry, i dont know what object you mean. Can you tell me how to find out the object-name you require? This works in excel as is (if you have the Mbt SDK installed). This is maybe not an AutoIt problem rather than me not fully understanding the VB code i posted.

I can use properties/methods/events of the moComMgr, moQuotes, moAcct etc. objects in my example in AutoIt with no problem, but i dont understand what IMbtQuotesNotify does or how to use it in AutoIt.

As far as i understand it, IMbtQuotesNotify is an interface from a typelibrary(MBTQUOTELib) with 4 methods in it. Those 4 methods are defined in VB procedures (IMbtQuotesNotify_OnQuoteData, IMbtQuotesNotify_OnLevel2Data, .. ) and are called whenever a new quote arrives, sort of like COM-events i can already use with the moComMgr object. Well, looks like i have to read up more about how com works after all..

Share this post


Link to post
Share on other sites

Well, Heres an example from the helpfile, for excel object, Might help you understand more about using com, like the layout and stuff.

$oExcel = ObjCreate("Excel.Application")                   ; Create an Excel Object
$oExcel.Visible = 1                                        ; Let Excel show itself
$oExcel.WorkBooks.Add                                      ; Add a new workbook
$oExcel.ActiveWorkBook.ActiveSheet.Cells(1,1).Value="test" ; Fill a cell
sleep(4000)                                                ;See the results for 4 seconds
$oExcel.ActiveWorkBook.Saved = 1                           ; Simulate a save of the Workbook
$oExcel.Quit                                               ; Quit Excel

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0