Sign in to follow this  
Followers 0
Wolfteeth

How to Call COM Interface not Object

16 posts in this topic

#1 ·  Posted (edited)

How to Call COM Interface not Object

Below is the info from Object Browser while I checked

Class IMessengerConversationWndAdvanced

Member of CommunicatorAPI

Messenger Conversation Window Advanced Interface

Class Messenger

Member of CommunicatorAPI

Messenger Object

I know how to create a Object like $oCommunicator = ObjCreate("CommunicatorAPI.Messenger")

but how to interactive with the Interface? $R = ObjCreate("CommunicatorAPI.IMessengerConverationWndAdvanced") doesn't work...

Actually, if its in VBA code, it just need to declare the data type like Dim r As CommunicatorAPI.IMessengerConversationWndAdvanced

but you know, there's no data type in AutoIT world.

see anyone can help?

Edited by Wolfteeth

Share this post


Link to post
Share on other sites



Object is object and interface is interface. You clearly don't know what either is and relation in between.

Get familiar with technical terms, meanings and representations. Then ask questions.

Only you wouldn't.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

You can't instantiate an interface. There's no code. It's just a set of prototypes.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Nono...I dont' fully think so, however, what I really want to know is how to declare the data type?

this is what VBA can do:

Sub sendMessage()
Dim p As CommunicatorAPI.Messenger
Dim r As CommunicatorAPI.IMessengerConversationWndAdvanced
Dim s As CommunicatorAPI.IMessengerContacts
Dim m As CommunicatorAPI.IMessengerContact
Dim w As String
Dim v As Long
Set p = CreateObject("Communicator.UIAutomation")
p.AutoSignin
Set s = p.MyContacts
Set m = p.GetContact("some@dummy.com",CStr(p.MyServiceId))
Set r = p.InstantMessage(m)
r.SendText ("hello from VBA Excel. ignore")
End Sub

but Autoit can only do the part of the above codes as it cannot declare the data type..

$oCommunicator = ObjCreate("Communicator.UIAutomation")
$s = $oCommunicator.Mycontacts
$m = $oCommunicator.GetContact("soneone@dumy.com", $oCommunicator.MyServiceID)
$rr = $oCommunicator.InstantMessage($m)

so, see anyone can help?

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

There is a mistake in the VBA-code. rr and r should be the same variable I think.


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

There is a mistake in the VBA-code. rr and r should be the same variable I think.

Dear, yes, it's typo issue. have corrected. you can tested it in your env, however, please remember to add the reference: Microsoft Office Communicaor 2007 API Type Library

reattach again:

Sub sendMessage()
Dim p As CommunicatorAPI.Messenger
Dim r As CommunicatorAPI.IMessengerConversationWndAdvanced
Dim s As CommunicatorAPI.IMessengerContacts
Dim m As CommunicatorAPI.IMessengerContact
Dim w As String
Dim v As Long
Set p = CreateObject("Communicator.UIAutomation")
p.AutoSignin
Set s = p.MyContacts
Set m = p.GetContact("some@dummy.com",CStr(p.MyServiceId))
Set r = p.InstantMessage(m)
r.SendText ("hello from VBA Excel. ignore")
End Sub

That is what I was confused that then how can I do the same thing in AutoIT...

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This is untested as I do not have Communicator on my PC. The code below is a direct translation from VB to AutoIt so it should work, Ive added a COM

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler


sendMessage()



Func sendMessage()
    Local $p
    Local $r
    Local $s
    Local $m
    Local $w
    Local $v

    $p = ObjCreate("Communicator.UIAutomation")
    $p.AutoSignin()
    $s = $p.MyContacts()
    $m = $p.GetContact("some@dummy.com", $p.MyServiceId)
    $r = $p.InstantMessage($m)
    $r.SendTexe("hello from VBA Excel. ignore")
EndFunc   ;==>sendMessage
; This is my custom error handler 


Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
                "Number is: " & $HexNumber & @CRLF & _
                "Windescription is: " & $oMyError.windescription ) 

Endfunc

Edit: Fixed tags

Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@Bowmore,

It's not working that displayed the error screen:

I think it is still related on the data type issue.

We intercepted a COM Error!

Number is: 80020006

Windescription is: Unknown name.

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

Change "e" to "t" in last method name. Isn't that obvious?


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Change "e" to "t" in last method name. Isn't that obvious?

O. Yes... SendText have been updated, another error is here.

We intercepted a COM Error!

Number is: 80004001

Windescription is: Unknown name.

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

Try this. It still wont work but I've changed the error output to give more information about where and why it is failing.

$oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Install a custom error handler

sendMessage()

Func sendMessage()
    Local $p
    Local $r
    Local $s
    Local $m
    Local $w
    Local $v

    $p = ObjCreate("Communicator.UIAutomation")
    $p.AutoSignin()
    $s = $p.MyContacts()
    $m = $p.GetContact("some@dummy.com", $p.MyServiceId)
    $r = $p.InstantMessage($m)
    $r.SendText("hello from VBA Excel. ignore")
EndFunc   ;==>sendMessage
; This is my custom error handler


Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is" & @TAB & @TAB & ": " & $HexNumber & @CRLF & _
            "Windescription is" & @TAB & ": " & $oMyError.windescription & @CRLF & _
            "source is"  & @TAB & @TAB & ": " & $oMyError.source & @CRLF & _
            "description is" & @TAB & ": " & $oMyError.description & @CRLF & _
            "helpfile is"  & @TAB & @TAB & ": " & $oMyError.helpfile & @CRLF & _
            "helpcontext is" & @TAB & ": " & $oMyError.helpcontext & @CRLF & _
            "lastdllerror is" & @TAB & ": " & $oMyError.lastdllerror & @CRLF & _
            "scriptline is" & @TAB & ": " & $oMyError.scriptline)
EndFunc   ;==>MyErrFunc

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

@Bowmore,

many thanks for your kindly replies and assistance, however, the problem is still exists.

I think need to think about the data type.

Error: 80004001

Windescription is : Not Implemented

source is :

description is :

helfile is :

helpcontext is:

lastdllerror is : 0

scriptline is : 19 ($r.SendText("hello from VBA Excel. ignore"))

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

At least we now know that the problem is with the SentText line.

Having searched MSDN for details of the Communicator Object model it would appear that there is no SendText() method implemented, as per the error message. Where did you get the VBA code from? Did it work? I looks as though you are going to have to use other means of sending you message, for example email or using AutoIt's Send() functions to send text to the messenger GUI.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

MSDN for the API, you can refer to

http://msdn.microsoft.com/en-us/library/bb787199(v=office.12).aspx

below is using the object browser to get the SendText function and it works.

post-9522-0-22532000-1301621597_thumb.pn

Edited by Wolfteeth

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

I think you'll need to call QueryInterface on the ibject in $r in order to get the advanced-interface. Something like:

$oWrapTemp = _AutoItObject_WrapperCreate(_AutoItObject_IDispatchToPtr($r), $dtagIUnknown)
$tIID = _AutoItObject_CLSIDFromString("{7C613A61-0633-4c69-AFF0-5BA9F1D28887}")
$rAdv = $oWrapTemp.QueryInterface(Number(DLLStructGetPtr($tIID)), 0)
$rAdv = _AutoItObject_PtrToIDispatch($rAdv[2])
$oWrapTemp = 0
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

@ProgAndy,

sorry, these days are busy on other that have no replies few days..

but its still need to say it is hard for me to understand..

$p = ObjCreate("Communicator.UIAutomation")
    $p.AutoSignin()
    $s = $p.MyContacts()
    $m = $p.GetContact("some@dummy.com", $p.MyServiceId)
    $r = $p.InstantMessage($m)
;    $r.SendText("hello from VBA Excel. ignore")

    $oWrapTemp = _AutoItObject_WrapperCreate(_AutoItObject_IDispatchToPtr($r), $dtagIUnknown)
    $tIID = _AutoItObject_CLSIDFromString("{7C613A61-0633-4c69-AFF0-5BA9F1D28887}")
    $rAdv = $oWrapTemp.QueryInterface(Number(DLLStructGetPtr($tIID)), 0)
    $rAdv = _AutoItObject_PtrToIDispatch($rAdv[2])
    $rAdv.SendText("hello from VBA Excel. ignore")
    $oWrapTemp = 0

when I run the code, it stops at $rADV = $oWrapTemp.QueryInterface. and the windescription is: "Variable must be of type 'Object'", Number is : 000000A9

I have also searched _AutoITobject_CLSIDfromString, not sure if we can use _CoCreateInstance directly?

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