Jump to content
Sign in to follow this  
AdmiralAlkex

[solved] COM sink object/IUnknown events (I don't know :S)

Recommended Posts

AdmiralAlkex

I wanted to see if I could manage to use IAppVisibility (Win8) in one of my scripts.

(it seems the name was changed in Release Preview but MSDN wasn't updated)

It took some time but I learned to make tlb file and made definitions for GetAppVisibilityOnMonitor and IsLauncherVisible methods (working good as far as I can tell), but I would like Advise and Unadvise too if possible, but I don't know how...

See definition on above link.

Only example I found is some (too advanced for me to translate) c++ code. Here. But it compiles and runs fine at least.

trancexx is doing a similar thing in maybe that can be used somehow?

Anyone have a clue?

Test script with the working funcs:

#include <WinAPI.au3>

;===============================================================================
#interface "IAppVisibility"
Global Const $sCLSID_AppVisibility = "{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}"
Global Const $sIID_IAppVisibility = "{2246EA2D-CAEA-4444-A3C4-6DE827E44313}"
; Definition
Global Const $tagIAppVisibility = "GetAppVisibilityOnMonitor hresult(ptr;int*);" & _
"IsLauncherVisible hresult(int*);" & _
"Advise hresult(ptr;dword*);" & _
"Unadvise hresult(dword);"
;==============================================================================

Local $oAppVisibility = ObjCreateInterface($sCLSID_AppVisibility, $sIID_IAppVisibility, $tagIAppVisibility)

;~ MsgBox(0, @ScriptName, IsObj($oAppVisibility))
;~ ConsoleWrite(IsObj($oAppVisibility) & @CRLF)

If Not IsObj($oAppVisibility) Then
ConsoleWrite("NOT IsObj" & @LF)
MsgBox(0, "", "NOT IsObj")
Exit
EndIf

HotKeySet("ö", "_IsLauncherVisible")
HotKeySet("å", "_GetAppVisibilityOnMonitor")

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

$callback=DllCallbackRegister("_MonitorEnumProc","int","ptr;ptr;ptr;lparam")
Global $Monitor
DllCall("user32.dll","int","EnumDisplayMonitors","ptr",0,"ptr",0,"ptr",DllCallbackGetPtr($callback),"lparam",10)

While 1
Sleep(1000)
WEnd

Func _IsLauncherVisible()
Local $bVisible
$iRet = $oAppVisibility.IsLauncherVisible($bVisible)
;~ If @error Then ;Enable this and disable AutoIt.Error if on Alpha
;~ MsgBox(0, @ScriptName, @error)
;~ EndIf
ToolTip("1: " & $iRet & @CRLF & "2: " & $bVisible)
EndFunc

Func _GetAppVisibilityOnMonitor()
Local $iMode
$iRet = $oAppVisibility.GetAppVisibilityOnMonitor($Monitor, $iMode)
ToolTip("1: " & $iRet & @CRLF & "2: " & $iMode)
EndFunc

; This is a custom error handler
Func ErrFunc()
$HexNumber = Hex($oMyError.number, 8)
MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
"Number is: " & $HexNumber & @CRLF & _
"WinDescription is: " & $oMyError.windescription)
$iEventError = 1 ; Use to check when a COM Error occurs
EndFunc ;==>ErrFunc

Func _MonitorEnumProc($hMonitor, $hdcMonitor, $lprect, $lparam)
MsgBox(0, "Monitor", "Monitor handle: " & $hMonitor & @CRLF & "LPARAM: " & $lparam)
$Monitor = $hMonitor
EndFunc

Here's tlb stuff:

==================================================================================

coclass AppVisibility;
CLSID = {7E5FE3D9-985F-4908-91F9-EE19F9FD1514};

// Implemented interface: <Interface> IAppVisibility

==================================================================================

Interface IAppVisibility;
IID = {2246EA2D-CAEA-4444-A3C4-6DE827E44313};
// Inherits from: IUnknown {00000000-0000-0000-C000-000000000046}

1.
STDCALL FUNC PUREVIRTUAL;
HRESULT GetAppVisibilityOnMonitor(
[in]
hMonitor,
[out] int* pMode
);

2.
STDCALL FUNC PUREVIRTUAL;
HRESULT IsLauncherVisible(
[out] int* pfVisible
);

3.
STDCALL FUNC PUREVIRTUAL;
HRESULT Advise(
[in]
* pCallback,
[out] dword* pdwCookie
);

4.
STDCALL FUNC PUREVIRTUAL;
HRESULT Unadvise(
[in] dword dwCookie
);


==================================================================================

enum MONITOR_APP_VISIBILITY;
{
MAV_UNKNOWN = 0,
MAV_NO_APP_VISIBLE = 1,
MAV_APP_VISIBLE = 2
};


==================================================================================

Interface IAppVisibilityEvents;
IID = {6584CE6B-7D82-49C2-89C9-C6BC02BA8C38};
// Inherits from: IUnknown {00000000-0000-0000-C000-000000000046}

1.
STDCALL FUNC PUREVIRTUAL;
HRESULT AppVisibilityOnMonitorChanged(
[in]
hMonitor,
[in]
previousMode,
[in]
currentMode
);

2.
STDCALL FUNC PUREVIRTUAL;
HRESULT LauncherVisibilityChange(
[in] int currentVisibleState
);


==================================================================================
Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
trancexx

You just have to realize that object is pointer to pointer pointing to set of function pointers. After that the soultion reveals itself.

I'll show you what I mean if no one else does it in the meantime, when I get home. You see, I'm at the beach now :D.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
ProgAndy

trancexx is doing a similar thing in maybe that can be used somehow?

Anyone have a clue?

I think you are on the right track, but the example is for IDispatch-Events. The event-interface for IAppVisibility is not that difficult and sophosticated. Create a DLLStruct for the object and the vTable-Struct with all methods using DLLCallbackRegister / ...GetPtr. Now just pass this reference to Advise. I'll hack something together on my Win8 VM :D

*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

This piece of code works for me. Some parts of _AppVisibilityEvents_GetPtr could be replaced with AutoItObject, but I think that would be overkill :D

#include <WinAPI.au3>


Global Const $sIID_IAppVisibilityEvents = "{6584CE6B-7D82-49C2-89C9-C6BC02BA8C38}"
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"
Global Const $sVTable_IAppVisibilityEvents = "ptr QueryInterface; ptr AddRef; ptr Release; ptr AppVisibilityOnMonitorChanged; ptr LauncherVisibilityChange;"

Func __AppVisibilityEvents_QueryInterface($pSelf, $pRIID, $pObj)
    #forceref $pSelf, $pRIID, $pObj
    ConsoleWrite("__AppVisibilityEvents_QueryInterface called " & $pSelf & "    " & _WinAPI_StringFromGUID($pRIID) & "    ")
    Local $tStruct = DllStructCreate("ptr", $pObj)
    Switch _WinAPI_StringFromGUID($pRIID)
        Case $sIID_IUnknown
            DllStructSetData($tStruct, 1, $pSelf)
            ConsoleWrite("IUnknown" & @CRLF)
            Return 0
        Case $sIID_IAppVisibilityEvents
            DllStructSetData($tStruct, 1, $pSelf)
            ConsoleWrite("IAppVisibilityEvents" & @CRLF)
            Return 0
    EndSwitch
    ConsoleWrite("~ E_NOINTERFACE" & @CRLF)
    Return 0x80004002 ; E_NOINTERFACE
EndFunc   ;==>__AppVisibilityEvents_QueryInterface

Func __AppVisibilityEvents_AddRef($pSelf)
    #forceref $pSelf
    ConsoleWrite("__AppVisibilityEvents_AddRef called" & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc   ;==>__AppVisibilityEvents_AddRef

Func __AppVisibilityEvents_Release($pSelf)
    #forceref $pSelf
    ConsoleWrite("__AppVisibilityEvents_Release called" & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc   ;==>__AppVisibilityEvents_Release

Func _AppVisibilityEvents_AppVisibilityOnMonitorChanged($pSelf, $hMonitor, $previousMode, $currentMode)
    ConsoleWrite("_AppVisibilityEvents_AppVisibilityOnMonitorChanged called: " & $hMonitor & " " & $previousMode & " " & $currentMode & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc

Func _AppVisibilityEvents_LauncherVisibilityChange($pSelf, $currentVisibleState);
    ConsoleWrite("_AppVisibilityEvents_LauncherVisibilityChange called: " & $currentVisibleState & @CRLF)
    Return 0x80004001 ; E_NOTIMPL
EndFunc

Func _AppVisibilityEvents_GetPtr()
    Local Static $tObj = DllStructCreate("ptr"), $tTable
    If Not DllStructGetData($tObj, 1) Then
        $tTable = DllStructCreate($sVTable_IAppVisibilityEvents)
        DllStructSetData($tObj, 1, DllStructGetPtr($tTable))
        DllStructSetData($tTable, 1, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_QueryInterface", "long", "ptr;ptr;ptr")))
        DllStructSetData($tTable, 2, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_AddRef", "long", "ptr")))
        DllStructSetData($tTable, 3, DllCallbackGetPtr(DllCallbackRegister("__AppVisibilityEvents_Release", "long", "ptr")))
        DllStructSetData($tTable, 4, DllCallbackGetPtr(DllCallbackRegister("_AppVisibilityEvents_AppVisibilityOnMonitorChanged", "long", "ptr;ptr;int;int")))
        DllStructSetData($tTable, 5, DllCallbackGetPtr(DllCallbackRegister("_AppVisibilityEvents_LauncherVisibilityChange", "long", "ptr;int")))
    EndIf
    Return DllStructGetPtr($tObj)
EndFunc



;===============================================================================
#interface "IAppVisibility"
Global Const $sCLSID_AppVisibility = "{7E5FE3D9-985F-4908-91F9-EE19F9FD1514}"
Global Const $sIID_IAppVisibility = "{2246EA2D-CAEA-4444-A3C4-6DE827E44313}"
; Definition
Global Const $tagIAppVisibility = "GetAppVisibilityOnMonitor hresult(ptr;int*);" & _
        "IsLauncherVisible hresult(int*);" & _
        "Advise hresult(ptr;dword*);" & _
        "Unadvise hresult(dword);"
;==============================================================================

Local $oAppVisibility = ObjCreateInterface($sCLSID_AppVisibility, $sIID_IAppVisibility, $tagIAppVisibility)

;~ MsgBox(0, @ScriptName, IsObj($oAppVisibility))
;~ ConsoleWrite(IsObj($oAppVisibility) & @CRLF)

If Not IsObj($oAppVisibility) Then
    ConsoleWrite("NOT IsObj" & @LF)
    MsgBox(0, "", "NOT IsObj")
    Exit
EndIf

Global $dwEventsCookie
$oAppVisibility.Advise(_AppVisibilityEvents_GetPtr(), $dwEventsCookie)
OnAutoItExitRegister("_UnadviseEvents")

HotKeySet("ö", "_IsLauncherVisible")
HotKeySet("å", "_GetAppVisibilityOnMonitor")

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

$callback=DllCallbackRegister("_MonitorEnumProc","int","ptr;ptr;ptr;lparam")
Global $Monitor
DllCall("user32.dll","int","EnumDisplayMonitors","ptr",0,"ptr",0,"ptr",DllCallbackGetPtr($callback),"lparam",10)

While 1
    Sleep(1000)
WEnd

Func _UnadviseEvents()
    $oAppVisibility.Unadvise($dwEventsCookie)
EndFunc

Func _IsLauncherVisible()
    Local $bVisible
    $iRet = $oAppVisibility.IsLauncherVisible($bVisible)
;~   If @error Then   ;Enable this and disable AutoIt.Error if on Alpha
;~       MsgBox(0, @ScriptName, @error)
;~   EndIf
    ToolTip("1: " & $iRet & @CRLF & "2: " & $bVisible)
EndFunc

Func _GetAppVisibilityOnMonitor()
    Local $iMode
    $iRet = $oAppVisibility.GetAppVisibilityOnMonitor($Monitor, $iMode)
    ToolTip("1: " & $iRet & @CRLF & "2: " & $iMode)
EndFunc

; This is a custom error handler
Func ErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    MsgBox(0, "", "We intercepted a COM Error !" & @CRLF & _
            "Number is: " & $HexNumber & @CRLF & _
            "WinDescription is: " & $oMyError.windescription)
    $iEventError = 1 ; Use to check when a COM Error occurs
EndFunc   ;==>ErrFunc

Func _MonitorEnumProc($hMonitor, $hdcMonitor, $lprect, $lparam)
    MsgBox(0, "Monitor", "Monitor handle: " & $hMonitor & @CRLF & "LPARAM: " & $lparam)
    $Monitor = $hMonitor
EndFunc

*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
AdmiralAlkex

I could kiss you guys, you are awesome! :D

Edit: PS, for anyone reading this thread in the future, there is also a dll alternative, IsImmersiveProcess in User32.dll

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
water

And girls :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
AdmiralAlkex

And girls :D

Oh, she's with us :huh:

guy

noun

a male. When used to refer to two or more people, the gender restriction is lifted such that one or more of those people may be female

Edited by AdmiralAlkex

Share this post


Link to post
Share on other sites
water

Oh, I learn something new every day :D


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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  

  • Similar Content

    • Bilgus
      By Bilgus
      ; NetFirewallPolicy2 COM UDF Library for AutoIt3
      ; AutoIt Version : 3.3.14.5
      ; Description ...: Windows Firewall Policy2 Interface, Provides access to the firewall policy for Windows Vista+
      Including Test Script 
      _NetFw_Get_CurrentProfileTypes                           Retrieves the currently active firewall profile(s) _NetFw_Get_FirewallEnabled                               Indicates whether a firewall is enabled locally _NetFw_Put_FirewallEnabled                               Specifies whether a firewall is enabled locally _NetFw_Get_ExcludedInterfaces                            Indicates a list of interfaces on which firewall settings are excluded _NetFw_Put_ExcludedInterfaces                            Specifies a list of interfaces on which firewall settings are excluded _NetFw_Get_BlockAllInboundTraffic                        Indicates whether the firewall should not allow inbound traffic _NetFw_Put_BlockAllInboundTraffic                        Specifies whether the firewall should not allow inbound traffic _NetFw_Get_NotificationsDisabled                         Indicates whether interactive firewall notifications are disabled _NetFw_Put_NotificationsDisabled                         Specifies whether interactive firewall notifications are disabled _NetFw_Get_UnicastResponsesToMulticastBroadcastDisabled  Indicates whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Put_UnicastResponsesToMulticastBroadcastDisabled  Specifies whether the firewall should not allow unicast responses to multicast and broadcast traffic _NetFw_Get_Rules                                         Retrieves the interface to collection of firewall rules _NetFw_Get_ServiceRestriction                            Retrieves the interface used to access the Windows Service Hardening store _NetFw_EnableRuleGroup                                   Enables or disables a specified group of firewall rules _NetFw_IsRuleGroupEnabled                                Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_RestoreLocalFirewallDefaults                      Restores the local firewall configuration to its default state _NetFw_Get_DefaultInboundAction                          Indicates the default action for inbound traffic _NetFw_Put_DefaultInboundAction                          Specifies the default action for inbound traffic _NetFw_Get_DefaultOutboundAction                         Indicates the default action for outbound traffic _NetFw_Put_DefaultOutboundAction                         Specifies the default action for outbound traffic _NetFw_Get_IsRuleGroupCurrentlyEnabled                   Determines whether a specified group of firewall rules are enabled or disabled for the current profile _NetFw_Get_LocalPolicyModifyState                        Determines if adding or setting a rule or group of rules will take effect in the current firewall profile  
      UDF:
      Test Script:
       
    • Bilgus
      By Bilgus
      I was Playing around With AutoIt this evening and wondered how hard it would be to get typeinfo like the COM Viewers do only using AutoIt
      Turns out it was pretty easy.
      A Few Notes:
      CAarray info is unfinished I didn't have any objects to test it on so I left it Limited.
      The Object must have IDispatch exposed (ITypeInfo is derivative)
      Its Just a proof of concept Run with it but don't carry scissors
      ITypeInfoCOM.au3
      ITypeInfoTest.au3
       
      Output IWebBrowserApp
       
      Output ObjCreate(MediaPlayer.MediaPlayer.1)
       
    • Bilgus
      By Bilgus
       IGroupPolicyObject interface
      ;;IGroupPolicyObject #RequireAdmin #include-once #include <WinAPIConstants.au3> ; $S_OK #include <WinAPIReg.au3> ;_WinAPI_GetRegKeyNameByHandle Global Enum $GPO_SECTION_ROOT = 0x0, $GPO_SECTION_USER, $GPO_SECTION_MACHINE Global Enum $GPO_OPEN_LOAD_REGISTRY = 0x1, $GPO_OPEN_READ_ONLY Global Enum $GPO_OPTION_DISABLE_USER = 0x1, $GPO_OPTION_DISABLE_MACHINE Global Enum $GPOTypeLocal = 0x0, $GPOTypeRemote, $GPOTypeDS, $GPOTypeLocalUser, $GPOTypeLocalGroup Global Const $sCLSID_GroupPolicyObject = "{EA502722-A23D-11D1-A7D3-0000F87571E3}" Global Const $sIID_IGroupPolicyObject = "{EA502723-A23D-11D1-A7D3-0000F87571E3}" Global Const $dtag_IGroupPolicyObject = _ "New hresult(wstr;wstr;dword);" & _ ; Creates a new GPO in the Active Directory with the specified display name. "OpenDSGPO hresult(wstr;dword);" & _ ; Opens the specified GPO and optionally loads the registry information. "OpenLocalMachineGPO hresult(dword);" & _ ; Opens the default GPO for the computer and optionally loads the registry information. "OpenRemoteMachineGPO hresult(wstr;dword);" & _ ; Opens the default GPO for the specified remote computer and optionally loads the registry information. "Save hResult(bool;bool;ptr;ptr);" & _ ; Saves the specified registry policy settings to disk and updates the revision number of the GPO. "Delete hresult();" & _ ; Deletes the GPO. "GetName hResult(wstr;int);" & _ ; Retrieves the unique name for the GPO. "GetDisplayName hResult(wstr;int);" & _ ; Retrieves the display name for the GPO. "SetDisplayName hresult(wstr);" & _ ; Sets the display name for the GPO. "GetPath hResult(wstr;int);" & _ ; Retrieves the path to the GPO. "GetDSPath hresult(dword;wstr;int);" & _ ; Retrieves the Active Directory path to the root of the specified GPO section. "GetFileSysPath hresult(dword;wstr;int);" & _ ; Retrieves the file system path (UNC format) to the root of the specified GPO section. "GetRegistryKey hresult(dword;handle);" & _ ; Retrieves a handle to the root of the registry key for the specified GPO section. "GetOptions hResult(dword*);" & _ ; Retrieves the options for the GPO. "SetOptions hresult(dword;dword);" & _ ; Sets the options for the GPO. "GetType hResult(dword*);" & _ ; Retrieves type information for the GPO being edited. "GetMachineName hResult(wstr;int);" & _ ; Retrieves the computer name of the remote GPO. "GetPropertySheetPages hresult(ptr;uint*);" ; Retrieves the property sheet pages associated with the GPO. Test() Func Test() Local $iResult Local $oIGroupPolicy Local $aGpoType[5] = ["Local", "Remote", "Active Directory", "LocalUser", "LocalGroup"] $oIGroupPolicy = ObjCreateInterface($sCLSID_GroupPolicyObject, $sIID_IGroupPolicyObject, $dtag_IGroupPolicyObject) While True If Not IsObj($oIGroupPolicy) Then ConsoleWrite("Failed To Retrieve Interface") $iResult = $E_NOINTERFACE ExitLoop Else ConsoleWrite("Success: " & ObjName($oIGroupPolicy, 1) & @CRLF) EndIf Local $sLoc, $sPath, $sName, $iType $tKey = DllStructCreate("handle hKey") $iResult = $oIGroupPolicy.OpenLocalMachineGPO(BitOR($GPO_OPEN_LOAD_REGISTRY, $GPO_OPEN_READ_ONLY)) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetDisplayName($sLoc, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetName($sName, 65535) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sLoc & " : " & $sName & @CRLF) $iResult = $oIGroupPolicy.GetPath($sPath, 65535) If $iResult <> $S_OK Then ExitLoop $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite($sPath & @CRLF) $iResult = $oIGroupPolicy.GetType($iType) If $iResult <> $S_OK Then ExitLoop ConsoleWrite("Type: " & $aGpoType[$iType] & @CRLF) $iResult = $oIGroupPolicy.GetRegistryKey($GPO_SECTION_USER, DllStructGetPtr($tKey)) If $iResult <> $S_OK Then ExitLoop ConsoleWrite(_WinAPI_GetRegKeyNameByHandle(DllStructGetData($tKey, "hKey")) & @CRLF) ExitLoop WEnd Return SetError($iResult, 0, ($iResult = $S_OK)) EndFunc ;==>Test Note: Not well tested..
    • Fenzik
      By Fenzik
       Hello all"
      I have curious problem with com object implementation of Sapi 5.1.
      In some cases }Some Voice engines] the metods for retrieve the voice parameters fails with error :Member not exists:.
      But the Retrieved Voice object can speak the given text, so It exists and work.
      Example of this type of Engine can be this one: http://download.kobavision.be/KobaSpeech3/KobaSpeech 3 With Vocalizer Serena - English (Great Britain).exe (can work as demo)
      So my question is> Is there some way to workaround or solve this issue?
      What i tryed:
      1. Typical use of Sapi.spvoice object:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
       
        $spvoice = ObjCreate("sapi.spvoice")
      for $voice in $spvoice.getvoices()
        msgbox(0, "Voice", $voice.getdescription())
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc

      2. Implement workaround based on Nvda Screen reader sapi5 Library at https://github.com/nvaccess/nvda/blob/master/source/synthDrivers/sapi5.py
      Thys code in Pascal should work, so i tryed to reproduce it in Autoit.
      Pascal code just as example:
                   SOTokens:=SpVoice.GetVoices('','');
                   for i:=0 to SOTokens.Count-1 do
                   try
                        SOToken:=SOTokens.Item(I); s:=SOToken.GetDescription(0);
      end
      In Autoit I tryed it like this:
      $oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler
        $spvoice = ObjCreate("sapi.spvoice")
      for $i = 0 to $spvoice.getvoices.count-1
      $name = $spvoice.getvoices.item($i).getdescription
      msgbox(0,"Voice", $name)
      next
      Func MyErrFunc()
      $HexNumber = hex($oMyError.number, 8)
      Msgbox(0,"","We intercepted a COM Error !" & @CRLF &"Number is: " & $HexNumber & @CRLF &"Windescription is: " & $oMyError.windescription)
      SetError(1)
      Endfunc
      Both of this methods returning same Error ("Member not exists.").
      Thanks a lot for help.
      Znefyg
    • gillesg
      By gillesg
      Hello,
       
      Is there a way to get all the properties and method of a COM object thru Autoit.
      I am looking in a way of display the imbricated structure of object and method.
       
      Example of COm objects are "itunes.application", "Shell.application" and so on.
      The idea is to have a code looking like
      $objtobrowse = objcreate("itunes.application") if isobj($objtobrowse) then $colItems = $objtobrowse.buildinproperty For $objItem In $colItems ConsoleWrite($objItem.<Name> & " - " & $objItem.<Value> & @CRLF) Next EndIf  
×