Sign in to follow this  
Followers 0
GMK

ObjGet (Beta) giving COM error

3 posts in this topic

Let's say I have multiple PowerTerm Pro windows open.

Global $oObj = ObjGet("", "PowerTermPro.Document") ; <-- Production command works ok for the first instance only
Global $oObj = ObjGet("", "PowerTermPro.Document", 1) ; <-- Beta command gives COM Error: 0x80020006 Unknown name.

Can anyone shed any light on this? How can I get access to multiple objects of the same class?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Use something like in the _ExcelBookAttach function?

$o_Result = ObjGet("", "Excel.Application")
 If @error Or Not IsObj($o_Result) Then
;~   ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application object" & @CRLF)
  Return SetError(1, 1, 0)
 EndIf
 Local $o_workbooks = $o_Result.Application.Workbooks
 If Not IsObj($o_workbooks) Or $o_workbooks.Count = 0 Then
;~   ConsoleWrite("--> Warning from function _ExcelAttach, No existing Excel.Application windows" & @CRLF)
  Return SetError(1, 2, 0)
 EndIf
 For $o_workbook In $o_workbooks
  Switch $s_mode
   Case "filename"
    If $o_workbook.Name = $s_string Then
     Return $o_workbook
    EndIf
   Case "filepath"
    If $o_workbook.FullName = $s_string Then
     Return $o_workbook
    EndIf
   Case "title"
    If ($o_workbook.Application.Caption) = $s_string Then
     Return $o_workbook
    EndIf
   Case Else
;~  ConsoleWrite("--> Error from function _ExcelAttach, Invalid Mode Specified" & @CRLF)
    Return SetError(1, 3, 0)
  EndSwitch
 Next
Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

To be able to send COM commands to the PowerTerm Pro object, the best way I've found so far is this:

; #FUNCTION# ====================================================================================================================
; Name ..........: _PTProAttach
; Description ...: Attach to the first PowerTerm Pro object
; Syntax ........: _PTProAttach()
; Parameters ....: None
; Return values .: On Success    - Returns an object variable pointing to a PowerTermPro.Document Application object
;                On Failure  - Returns 0 and sets @error:
;                |@error     - 0 ($_PTProStatus_Success) = No Error
;                |@error     - 1 ($_PTProStatus_GeneralError) = General Error
; Author ........: GMK
; ===============================================================================================================================
Func _PTProAttach()
Local $sFuncName = "_PTProAttach"
Local $oDoc = ObjGet("", "PowerTermPro.Document")
If Not IsObj($oDoc) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
EndIf
$oDoc.ShowApplication
Local $oReturn = $oDoc.GetApplication
If Not IsObj($oReturn) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
EndIf
Return SetError($_PTProStatus_Success, 0, $oReturn)
EndFunc ;==>_PTProCreate

; #FUNCTION# =====================================================================================================================
; Name ..........: _PTProCreate
; Description ...: Creates a PowerTerm Pro object
; Syntax ........: _PTProCreate([$sSetupFile = ""[, $iCommType = ""[, $sTerminalName = ""[, $sHost = ""[, $sPort = ""]]]]])
; Parameters ....: $sSetupFile - [Optional] PowerTerm Pro setup file location
;                $iCommType  - [Optional] Comm Type:
;                                            $pt_Telnet  = 0
;                                            $pt_Com         = 1
;                                            $pt_Nsvt    = 2
;                                            $pt_Lat         = 3
;                                            $pt_Cterm   = 4
;                                            $pt_Bapi    = 5
;                                            $pt_Rlogin  = 6
;                                            $pt_TAPI    = 7
;                                            $pt_Superlat = 8
;                                            $pt_Nwlat   = 9
;                                            $pt_Tn3270  = 10
;                                            $pt_Mssna   = 11
;                                            $pt_Nwsaa_ipx = 12
;                                            $pt_Nwsaa_TCPIP = 13
;                                            $pt_Tn5250  = 14
;                                            $pt_Nsrouter = 15
;                                            $pt_Winappc     = 16
;                $sTerminalName - [Optional] Terminal Name
;                $sHost      - [Optional] Host (IP or DNS Address)
;                $sPort      - [Optional] Port
; Return values .: On Success    - Returns an object variable pointing to a PowerTermPro.Document Application object
;                On Failure  - Returns 0 and sets @error:
;                |@error     - 0 ($_PTProStatus_Success) = No Error
;                |@error     - 1 ($_PTProStatus_GeneralError) = General Error
;                |@error     - 3 ($_PTProStatus_InvalidDataType) = Invalid Data Type
;                |@error     - 4 ($_PTProStatus_InvalidValue) = Invalid Value
;                |@error     - 5 ($_PTProStatus_FileNotFound) = File Not Found
;                |@extended  - Contains invalid parameter number
; Author ........: GMK
; ================================================================================================================================
Func _PTProCreate($sSetupFile = "", $iCommType = "", $sTerminalName = "", $sHost = "", $sPort = "")
Local $sFuncName = "_PTProCreate"
Local $oDoc = ObjCreate("PowerTermPro.Document")
If Not IsObj($oDoc) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
EndIf
If $sSetupFile <> "" And Not FileExists($sSetupFile) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_FileNotFound")
Return SetError($_PTProStatus_FileNotFound, 1, 0)
EndIf
If $iCommType <> "" And Not IsInt($iCommType) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 2, 0)
EndIf
If $iCommType <> "" And Not ($iCommType >= 0 And $iCommType <= 16) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue")
Return SetError($_PTProStatus_InvalidValue, 2, 0)
EndIf
If $sTerminalName <> "" And Not IsString($sTerminalName) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 3, 0)
EndIf
If $sHost <> "" And Not IsString($sHost) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 4, 0)
EndIf
If $sHost <> "" And Ping($sHost) = 0 Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidValue")
Return SetError($_PTProStatus_InvalidValue, 4, 0)
EndIf
If $sPort <> "" And Not IsString($sPort) Then
__PTProErrorNotify("Error", $sFuncName, "", "$_PTProStatus_InvalidDataType")
Return SetError($_PTProStatus_InvalidDataType, 5, 0)
EndIf
$oDoc.ShowApplication
Local $oReturn = $oDoc.GetApplication
If Not IsObj($oReturn) Then
__PTProErrorNotify("Error", $sFuncName, "", "PowerTermPro.Document Application Object Creation Failed")
Return SetError($_PTProStatus_GeneralError, 0, 0)
EndIf
Switch $iCommType
Case 0
_PTProSessionSetTelnetParameters($oReturn, $sTerminalName, $sHost, $sPort)
Case 1 To 16
_PTProSessionSetCommType($oReturn, $iCommType)
_PTProSessionSetTerminalName($oReturn, $sTerminalName)
_PTProSessionSetHostName($oReturn, $sHost)
_PTProSessionSetCommPort($oReturn, $sPort)
EndSwitch
_PTProSessionOpen($oReturn)
If $sSetupFile <> "" Then _PTProOpenSetupFile($oReturn, $sSetupFile)
If $sHost <> "" And Not _PTProIsCommunicationOpen($oReturn) Then __PTProErrorNotify("Warning", $sFuncName, "", "Unable to connect to server.")
Return SetError($_PTProStatus_Success, 0, $oReturn)
EndFunc ;==>_PTProCreate


So it's very backwards--create or attach to a "document," then get the application from there and you can send your commands.

Edited by GMK

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

  • Similar Content

    • qsek
      By qsek
      Can somebody try to reproduce this bug?
      It would be helpful to know if this issue appeares on other environments too.
      Issue:
      Sometimes values of certain keys will return empty even if expicitly assigned a value before.
      Conditions:
      Map is bigger than ~50 key/values pairs value is being worked with in a Function where a loop is iterating through the Map before retrieving the value there is a isMap/MapKeys/MapAppend/MapRemove check on the Map value. Dim $mMap[] ; Generate random key strings For $i = 0 To 100 $RndKey = "" For $i2 = 0 To 4 $RndKey &= Chr(Random(65,90,1)) Next $mMap[$RndKey] = 999 next ConsoleWrite("-----------1-------------" & @CRLF); Unpredictable blank values MapDisplay1($mMap) ConsoleWrite("-----------2-------------" & @CRLF); ByRef always works MapDisplay2($mMap) ConsoleWrite("-----------3-------------" & @CRLF); not in a function always works For $i In MapKeys($mMap) isMap($mMap[$i]) ConsoleWrite($i&": "&$mMap[$i]&@CRLF) Next Func MapDisplay1( $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ;same problem with isMap($m_Map[$i]), MapKeys($m_Map[$i]), MapAppend/MapRemove but NOT with MapExists($m_Map,$i) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc Func MapDisplay2( ByRef $m_Map ) For $i In MapKeys($m_Map) isMap($m_Map[$i]) ConsoleWrite($i&": "&$m_Map[$i]&@CRLF) Next EndFunc  
      The value is not lost or overwritten on the global map, only on the local map inside the function.
       
    • WoodGrain
      By WoodGrain
      Hi All,
      I've coded the small script below, but it can't seem to get the instance of Windows Media player as it keeps going to @error, I've not used com objects before so any assistance would be appreciate. I already have WMP open and minimised. I retrieved "WMPlayerApp" from the AutoIT info tool, I've included a copy below.
      I'm using these sources:
      https://msdn.microsoft.com/en-us/library/dd564085.aspx
      https://msdn.microsoft.com/en-us/library/dd564018.aspx
      $oWMP = ObjGet("", "WMPlayerApp") If @error Then MsgBox(0, "Can't get WMP", "Couldn't connect to the WMP instance") Exit EndIf $wmpPlayState = $oWMP.playState MsgBox(0, "Play State", $wmpPlayState) $wmpSongName = $oWMP.currentMedia.name MsgBox(0, "Play State", $wmpSongName) I've also seen references to the below, but I want to get an existing open WMP:
      ObjCreate("wmplayer.OCX") and have looked at the WMP.udf but can't see how it will do either of the functions I've coded above.
       
    • TheDcoder
      By TheDcoder
      Hello Again! I previously stumbled upon a topic asking for maps datatype's instructions... I too wasn't sure what a map is until I tried it... So I am making this topic to help other newbies (and some oldbies) better understand the Maps datatype of AutoIt! Lets start!
      A Note for Readers
      The maps datatype is still in development and is currently in Alpha Stage (More Risky than Beta) and its unstable, so AutoIt can crash indefinably while using Maps! I can't guarantee if this will be implemented in stable versions, this is a fairly new thing to AutoIt coders & in my honest opinion I don't see any use for it Maps are the best datatype in AutoIt, Very Useful ... Not hurting anyone though .  Also the maps datatype is DISABLED IN STABLE VERSIONS, So you need to install the latest beta version of AutoIt to make maps work . If you find any bugs while using a map, please report it in the Official Bug Tracker
      Introduction To Maps
      Maps are just like arrays, instead they use "keys" to access elements inside them... A key can be either a string or an integer (Other datatypes work too but they are converted to a integer [Equivalent to Int($vKey)] before assignment [Source]). Although Integers don't represent the order of elements in a map unlike in an array...
      Declaring Maps
      Its similar to declaring an Array:
      ; This is the only way to declare a map ; You must have a declarative keyword like Dim/Global/Local before the declaration unless the map is assigned a value from a functions return Local $mMap[] ; Don't insert any numbers or strings it! Simple, Isn't it?
      Using Maps
      Using maps is similar to arrays (again!):
      Local $mMap[] ; Lets declare our map first! ; Adding data to maps is easy... ; This is our key ; | ; v $mMap["Key"] = "Value" ; <--- And our value! ; A key is Case-Sensitive meaning "Key" is not same as "key"! $mMap["key"] = "value" ; Not the same as $mMap["Key"]! ; There are 2 different ways to access an element in a map $mMap["Key"] ; 1st Method $mMap.Key ; 2nd Method  Enumerating Maps
      Its quite easy to enumerate through arrays but what about maps? how can I enumerate through them!?
      #include <MsgBoxConstants.au3> ; Lets create our map first Local $mMap[] ; Lets add some information to the map, feel free to modify & add new elements $mMap["Name"] = "Damon Harris" $mMap["Alias"] = "TheDcoder" $mMap["Gender"] = "Male" $mMap["Age"] = 14 $mMap["Location"] = "India" $aMapKeys = MapKeys($mMap) ; MapKeys function returns all the keys in the format of an array Local $sProfile = "Profile of " & $mMap["Name"] & ':' & @CRLF ; We will use this string later For $vKey In $aMapKeys ; We use this to get the keys in a map :) $sProfile &= @CRLF & $vKey & ': ' & $mMap[$vKey] ; Add some details to the profile string using our map! Next MsgBox($MB_ICONINFORMATION + $MB_OK, "Profile", $sProfile) ; Finally display the profile :) It is easy as always
      Multi-Dimensional Maps
      Now now... I know that you are a little confused that how can an multi-dimensional maps exist... Although I am not 100% sure if its called that but lets continue:

      #include <MsgBoxConstants.au3> ; Multi-Dimensional maps are just maps in a map Local $mMapOfMapsvilla[] ; This map will store an other map Local $mParkMap[] ; This Park map will be inserted in the Mapsvilla's map :P $mMapOfMapsvilla["Map Item 1"] = "Town Hall" $mMapOfMapsvilla["Map Item 2"] = "Police Station" $mMapOfMapsvilla["Map Item 3"] = "Shopping Mall" $mMapOfMapsvilla["Map Item 4"] = "Residential Area" $mMapOfMapsvilla["Map Item 5"] = "Park" $mParkMap["Map Item 1"] = "Cottan Candy Stand" $mParkMap["Map Item 2"] = "Public Toilet" $mParkMap["Map Item 3"] = "Woods" $mMapOfMapsvilla.Park = $mParkMap MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla["Map Item 1"]) ; Will display Town Hall MsgBox($MB_OK, "Map Location", $mMapOfMapsvilla.Park["Map Item 1"]) ; Will display Cottan Candy Stand I am sure its easy for you to understand now
      Frequently Asked Questions (FAQs) & Their answers
      Q #1. Help! My code does not respond to anything (or) I get an "Variable subscript badly formatted" error on the line of declaration...
      A. DONT USE F5 or Go, Instead use Alt + F5 or Tools -> Beta Run in SciTE (Make sure that you have Beta installed)
      Q #2. Why are you using "m" in-front of every map variable?
      A. Best coding Practices: Names of Variables 
      Q #3. What are "Elements" which you mention frequently???
      A. This is a newbie question (I have no intention of insulting you ), so I guess you are new to programming. "Elements" are data slots inside a Map (or an Array), you can imagine elements as individual variable which are stored in a Map. You can access them using "keys", Please refer to "Introduction to Maps" section at the starting of this post
      Q #4. Are Maps faster than Arrays?
      A. You need to understand that Maps have different purpose than Arrays. Maps are designed to store data dynamically (like storing information for certain controlIDs of GUI) and Arrays are designed to store data in a order (for instance, Storing every character of a string in an element for easy access). If you still want to know then if Maps are faster, then the answer is maybe... Maps are *supposed* (I am not sure ) to be faster in addition of elements (while Arrays are painfully slow while adding or removing elements). Here (Post #24) is a benchmark (Thanks kealper! )
       
      More FAQs coming soon! Feel free to ask a question in the mean while
    • TheDcoder
      By TheDcoder
      Hello! I was wonder if it OK for me to use datatypes other than strings & integers... I tested it and it works! But the help file states: (Beta Helpfile -> AutoIt -> Language Reference -> Variables)
      So yeah, will I able to continue using other datatypes normally even in the future releases of AutoIt?
       
      Thanks in Advance! TD
    • kingjacob90
      By kingjacob90
      HI
      I am wanting to know what my CPU temp is but don't know what object to use. I don't relay know how objget works so would not know where to start. I have seen people integrate things like windows speech to text into their scripts but don't know how they know what object to use! How do I find the right object? And how dose it work?
       
      Thanks Jacob