Jump to content
Sign in to follow this  
1RV34

Calls to "_class::property" stuff

Recommended Posts

1RV34

Well I asked it before in an other topic but no one replies there so I thought I'll start it as a seperate topic.

Ok I'm kinda stuck & hope somebody can help me with this here.

I'm following this tutorial but I can't get stuff to work.

I have a dll & it has like COM Properties or idk like "_class::propperty" but how do I call them?

using DLLCall (like I tried) or do I need the ObjGet function? Or both of them combined?

I haven't used dll's & com stuff before but now I need to and now this tutorial did help me understand DLLCall better.

Anybody can push me in the right direction? Do I need DLLCall or ObjGet or both? And how do I use those things from the dll (those that look like "_class::property") in AutoIt?

Edit: I also found a function called "DllGetClassObject" in the dll, can I use that to create an object and then use that to call the properties? If so how?

When I tried it myself it crashed with exit code -1073741819.

Edit: I now noticed some of them are methods and others properties, can I both use methods and get properties?

Edited by 1RV34

MsgBox(0x40040, "", "Hello Forum!")

Share this post


Link to post
Share on other sites
1RV34

Some aditional information:

Using a DLL viewer I saw these functions:

  • DllCanUnloadNow
  • DllGetClassObject
  • DllRegisterServer
  • DllUnregisterServer
Which indicate I can register the DLL using
regsvr32 "C:pathtothedll.dll"
and I think I should then be able to use ObjCreate("obj.type") to continue.

But how do I find that "obj.type" and then call to "_clsClass::mtdMethod" & "_clsClass::prpProperty"?

I'm really stuck and any hint or push in the right direction would help a lot :/


MsgBox(0x40040, "", "Hello Forum!")

Share this post


Link to post
Share on other sites
smartee

hi 1RV34,

ObjCreate is fine for COM objects.

Unfortunately you gave us very little (relevant, specific) information ;) so that's about all the help I can offer at the moment.

What is the name of the dll? Where can one find it? and its documentation?

Also, please post the code you tried, and any errors you might have encountered.

Help us help you :)

-smartee

Share this post


Link to post
Share on other sites
MilesAhead

If the COM dll was compiled with type information you should be able to load it into a Type Library Viewer to see the supported interfaces. Basically if the library is really an ActiveX Control or has Automation support, you can load from a scripting language. Otherwise if it's virtual method table only, you need to access it from a compiled language. If it supports Automation chances are it has a Type Library. So try a Type Library viewer. I'm sure you can download a free one someplace.

It's been quite a few years since I did COM programming. So this is just from vague memory. Hope I pointed you in the right direction.

Edited by MilesAhead

Share this post


Link to post
Share on other sites
1RV34

What is the name of the dll? Where can one find it? and its documentation?

The name is "SnelStartGateWay.dll". It is ment to make communication between your program and SnelStart possible.

It can be found in "C:Program Files (x86)SnelStartV1000" (V1000 is version dependable but my script finds the right path). It comes with the program.

The documentation is in Dutch so I don't know if that will help you much, but what I can do is give the (vb6) example in it if that might help.

Private Sub mtdToevoegenJournaalPost()
  On Error GoTo ErrorHandler
  'Declaratie variabelen
  Dim mvrGWaySnelStart As clsGWaySnelStart
  Dim mvrAdmiInEuro As Boolean
  Dim mvrGbOmschrijving As String
  'Aanmaken nieuwe ToegangsObject
  Set mvrGWaySnelStart = New clsGWaySnelStart
  With mvrGWaySnelStart
    'Openen administratie
    .mtdGWayAdmiOpenen "C:SnelStartAdministraties", "SnelStart Voorbeeldbedrijf"
    'Uitlezen of Administratie in Euro's is
    mvrAdmiInEuro = .prpGWayAdmiInEuroGet
    Debug.Print "Adminitratie in Euro is " & mvrAdmiInEuro
    'Uitlezen omschrijving van Grootboek 9990
    mvrGbOmschrijving = .mtdGWayGrootboekOmschrijving(9990)
    Debug.Print "Omschrijving van GrootBoek 9990 is " & mvrGbOmschrijving
    'Journaalpost openen
    .mtdGWayJpAanmaken Now, 9990, "ABC", "OmschrijvingXYZ"
    'Regels aan JournaalPost toevoegen
    .mtdGWayJpRegelToevoegenV616 8001, "DebetZZZZ", 100, 0
    .mtdGWayJpRegelToevoegenV616 8002, "CreditYYYY", 0, 75
    .mtdGWayJpRegelToevoegenV616 8002, "CreditYYYY", 0, 25
    'Journaalpost sluiten
    .mtdGWayJpSluiten
    'Sluiten administratie
    .mtdGWayAdmiSluiten
    'Starten applicatie
    .mtdGWayRunSnelStart "C:SnelStartAdministratiesSnelStart Voorbeeldbedrijf"
  End With
  Exit Sub
ErrorHandler:
  mtdMsg mtdGWayFoutBoodschap("mtdToevoegenJournaalPost"), vbInformation
End Sub

Private Sub mtdWijzigenJournaalPost()
  On Error GoTo ErrorHandler
  'Declaratie variabelen
  Dim mvrGWaySnelStart As clsGWaySnelStart
  Dim mvrGWayJournaalPost As clsGWayJournaalPost
  Dim mvrGWayJournaalRegel As clsGWayJournaalRegel
  'Aanmaken nieuwe ToegangsObject
  Set mvrGWaySnelStart = New clsGWaySnelStart
  With mvrGWaySnelStart
    'Openen administratie
    .mtdGWayAdmiOpenen "C:SnelStartAdministraties", "SnelStart Voorbeeldbedrijf"

    '-----------------------------------------------------
    'Voorbeeld 1 met verwijderen van een journaalpostregel
    '-----------------------------------------------------
    Set mvrGWayJournaalPost = .mtdGWayJournaalPostGet(502)
    'Wijzig het GrootboekNummer op vierde journaalpostregel
    mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(4).prpGWayGrootboekNummerSet = 3006
    'Voeg 4e en 5e journaalpostregel samen
    mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(4).prpGWayDebetSet = mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(4).prpGWayDebetGet + _
                                                                        mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(5).prpGWayDebetGet
    mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(4).prpGWayCreditSet = mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(4).prpGWayCreditGet + _
                                                                         mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(5).prpGWayCreditGet
    'Verwijder de 5e journaalpostregel
    mvrGWayJournaalPost.mtdJpRegelRemove 5
    'Voer wijziging door
    .mtdGWayJpWijzigen mvrGWayJournaalPost

    '---------------------------------------------------
    'Voorbeeld 2 met toevoegen van een journaalpostregel
    '---------------------------------------------------
    Set mvrGWayJournaalPost = .mtdGWayJournaalPostGet(503)
    'Wijzig totaalbedrag
    mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(1).prpGWayDebetSet = mvrGWayJournaalPost.mtdGetJournaalRegelOpIndex(1).prpGWayDebetGet + 100
    'Voeg extra regel toe
    Set mvrGWayJournaalRegel = mvrGWayJournaalPost.mtdJpRegelAdd
    'Vul de nieuwe regel
    mvrGWayJournaalRegel.prpGWayDebetSet = 0
    mvrGWayJournaalRegel.prpGWayCreditSet = 100
    mvrGWayJournaalRegel.prpGWayBtwIDSet = encGWayBtwIDGeen
    mvrGWayJournaalRegel.prpGWayBtwPercentageSet = 0
    mvrGWayJournaalRegel.prpGWayBtwTypeSet = encGWayBtwTypeNvt
    mvrGWayJournaalRegel.prpGWayFactuurNummerSet = "20050918"
    mvrGWayJournaalRegel.prpGWayFactuurRelatiecodeSet = 2
    mvrGWayJournaalRegel.prpGWayGrootboekNummerSet = 8095
    mvrGWayJournaalRegel.prpGWayOmschrijvingSet = "extra regel"
    'Voer wijziging door
    .mtdGWayJpWijzigen mvrGWayJournaalPost

    'Sluiten administratie
    .mtdGWayAdmiSluiten
    'Starten applicatie
    .mtdGWayRunSnelStart "C:SnelStartAdministratiesSnelStart Voorbeeldbedrijf"
  End With
  Exit Sub
ErrorHandler:
  mtdMsg mtdGWayFoutBoodschap("mtdWijzigenJournaalPost"), vbInformation
End Sub

Private Sub mtdInkoopOrderToevoegen()
  On Error GoTo ErrorHandler
  'Declaratie variabelen
  Dim mvrGWaySnelStart As clsGWaySnelStart
  Dim mvrGWayJournaalPost As clsGWayJournaalPost
  Dim mvrGWayJournaalRegel As clsGWayJournaalRegel
  'Aanmaken nieuwe ToegangsObject
  Set mvrGWaySnelStart = New clsGWaySnelStart
  With mvrGWaySnelStart
    'Openen administratie
    .mtdGWayAdmiOpenen "C:SnelStartAdministraties", "SnelStart Voorbeeldbedrijf"

    'Inkooporder aanmaken
    .mtdGWayInkoopOrderAanmaken 1, 30123, Now, "Inkoop via gateway", "memo-tekst", "bk inkoop"
    'Regels toevoegen
    .mtdGWayInkoopOrderRegelToevoegenArtikelMetDefaults 12, 100
    .mtdGWayInkoopOrderRegelToevoegenArtikel 12, "Eigen omschrijving", 50, 1.12, 10, 1
    .mtdGWayInkoopOrderRegelToevoegenTekst "Echte tekstregel", 0, 0
    .mtdGWayInkoopOrderRegelToevoegenTekst "Tekstregel met bedrag en kostenplaats", 10, 2
    'Voer wijziging door
    .mtdGWayInkoopOrderSluiten

    'Sluiten administratie
    .mtdGWayAdmiSluiten
    'Starten applicatie
    .mtdGWayRunSnelStart "C:SnelStartAdministratiesSnelStart Voorbeeldbedrijf"
  End With
  Exit Sub
ErrorHandler:
  mtdMsg mtdGWayFoutBoodschap("mtdWijzigenJournaalPost"), vbInformation
End Sub

Private Sub mtdVerkoopAbonnementOrderToevoegen()
  On Error GoTo ErrorHandler
  'Declaratie variabelen
  Dim mvrGWaySnelStart As clsGWaySnelStart

  Dim mvrSjabloonID As Long
  Dim mvrRelatieCode As Long
  Dim mvrDatum As Date
  Dim mvrOmschrijving As String
  Dim mvrOrderMemo As String
  Dim mvrKostenplaatsenNummer As Long
  Dim mvrBetalingsKenmerk As String
  Dim mvrVerkoperLoginNaam As String

  Dim mvrAbonnementIntervalSoort As enmGWayAbonnementInterval
  Dim mvrAbonnementIntervalAantal As Variant
  Dim mvrAbonnementTijdstipMaand As Variant
  Dim mvrAbonnementTijdstipWeekDag As Variant
  Dim mvrAbonnementTijdstipMaandDag As Variant
  Dim mvrAbonnementTijdstipWeekVanMaandDag As Variant
  Dim mvrAbonnementBegindatum As Variant
  Dim mvrAbonnementEindDatum As Variant
  Dim mvrAbonnementEindeNaAantal As Variant

  'Aanmaken nieuwe ToegangsObject
  Set mvrGWaySnelStart = New clsGWaySnelStart
  With mvrGWaySnelStart
    'Openen administratie
    .mtdGWayAdmiOpenen "C:SnelStartAdministraties", "SnelStart Voorbeeldbedrijf"

    'Verkooporder aanmaken
    mvrSjabloonID = 1
    mvrRelatieCode = 10001
    mvrDatum = Now
    mvrOrderMemo = "memo"
    mvrKostenplaatsenNummer = 0
    mvrBetalingsKenmerk = "BK"

Also, please post the code you tried, and any errors you might have encountered.

I have tried some codes, none worked (they are probably very noobish because I have never used them before).

Codes i tried:

$dll = DllOpen($dllPath)

If $dll = -1 Then
    _Err("Kon SnelStartGateWay.dll niet openen!")
EndIf

$result = DllCall($dll, "none", "_clsGWaySnelStart::mtdGWayAdmiOpenen"); also tried "DllGetClassObject" as function, this made AutoIt time-out/crash after a while
$error = @error

If $error Then
    _Err("DLLCall #1 Error: " & $error)
EndIf

_Msg("DLLCall #1 Result: " & $result)
DllClose($dll)

$obj = ObjCreate("SnelStartGateWay.application")
$error = @error

If $error Then
    _Msg("SnelStart Sync maakt een poging om SnelStartGateWay.dll te registreren." & @LF & "Druk op OK.")
    Break(0)
    RunWait('regsvr32 "' & $dllPath & '"')
    $obj = ObjCreate("SnelStartGateWay.application")
    $error = @error

    If $error Then
        Run('regsvr32 /u "' & $dllPath & '"')
    EndIf

    Break(1)

    If $error Then
        _Err("ObjCreate #1 Error: " & $error)
    EndIf
EndIf

$dll = _WinAPI_LoadLibrary($dllPath)

If $dll Then
    ; ... (didn't know what i would have to do here :P)
_WinAPI_FreeLibrary($dll)
Else
    _Err("Kon SnelStartGateWay.dll niet openen!"); it did not give this error message tho XD
EndIf

MsgBox(0x40040, "", "Hello Forum!")

Share this post


Link to post
Share on other sites
MilesAhead

Does the VB6 code work? If not then the dll is likely not registered on the system. Search the registry for the string you use in ObjCreate() function. If that string is not found then it's not registered. Try regsvr32 or one of those shell extensions that registers and unregisters COM libraries.

edit: also if it's a licensed ActiveX Control designed to drop on a form such as in VB6, it won't work without the .lic file. It would need a design time license before it would instantiate on the form(the .lic file.) A program using it will run but you can't use it in a form designer without the license if it's a licensed control.

First thing I'd do is try to get the VB6 example to go. If it doesn't you're likely wasting your time.

Edited by MilesAhead

Share this post


Link to post
Share on other sites
smartee

Hi 1RV34,

Now that's a greatly informative post! :)

I don't understand a word of dutch however ;) , but with Google Translate I managed to cobble up a couple lines to get you started,

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

$oSnel = ObjCreate("SnelStartGateWay.clsGWaySnelStart")
If IsObj($oSnel) Then
    MsgBox(64, "", "Object created successfully")
EndIf

MsgBox(64, "Version", $oSnel.prpGWayVersieGateWayGet())

$oSnel2 = ObjCreate("SnelStartGateWay.clsGWArtikel")
If IsObj($oSnel2) Then
    MsgBox(64, "", "Object created successfully")
EndIf

; This is the 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 & @CRLF & _
            "Source is: " & $oMyError.source & @CRLF & _
            "Description is: " & $oMyError.description & @CRLF & _
            "Helpfile is: " & $oMyError.helpfile & @CRLF & _
            "Helpcontext is: " & $oMyError.helpcontext & @CRLF & _
            "Lastdllerror is: " & $oMyError.lastdllerror & @CRLF & _
            "Scriptline is: " & $oMyError.scriptline)
EndFunc   ;==>MyErrFunc

Hope this little tidbit helps ;)

-smartee

Edit: some spelling, greets

Edited by smartee

Share this post


Link to post
Share on other sites
1RV34

Yes

$oSnel = ObjCreate("SnelStartGateWay.clsGWaySnelStart")

Just that line helped a lot already!

I didn't know which function I needed (DllCall, ObjCreate or _WinAPI_LoadLibrary) and also if I needed ObjCreate I didn't know I needed "SnelStartGateWay.clsGWaySnelStart" I tried stuff like "SnelStartGateWay.application" XD (never used it before o.o)

Thanks for this example & making me understand ObjCreate more! :oops:


MsgBox(0x40040, "", "Hello Forum!")

Share this post


Link to post
Share on other sites
MilesAhead

The name of the automation used for IDispatch is always in the registry somewhere as a clsid. For instance if you have Scripting Dictionary installed you'll see "Scripting.Dictionary" defined somewhere. Usually things that support IDispatch have type library information. Languages like C++ often you can import the type library and the Intellisense will automatically pick up the methods once you create an instance. A lot of program code is in English when the language of origin is not just because so many compilers etc.. were created in English.

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 
      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..
    • Bilgus
      By Bilgus
      So first things first the example in the help file for _WinApi_Enum_Windows has an error
      ;_ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, Default, "#|Handle|Class|Title|Text|Process") Should Be _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process") Next is a bit of helpful info on LPCSTR in a callback function it needs  to be passed as a PTR
      DllCallbackRegister($sFUNCT, $sRETURN, "ptr") Finally on to my question
      I'd want to call EnumPropsEX and pass a string through lparam + append to it rather than declaring anything globally
      I can Come up with two ways to do this The second it a lot more code but possibly safer but the first way I think Should do
      1. From a bit of testing It seems AutoIt won't overflow a DllStruct?
      2. Are strings passed through DLL call guaranteed to be 'an ANSI string (a minimum of 65536 chars is allocated)' as the Helpfile clearly states?
      #include <Array.au3> #include <WinAPI.au3> Example() Func Example() Local $aWindows = _WinAPI_EnumWindows() Local $aResult[$aWindows[0][0]][6] For $i = 1 To $aWindows[0][0] $aResult[$i - 1][0] = "0x" & Hex($aWindows[$i][0], 8) $aResult[$i - 1][1] = $aWindows[$i][1] $aResult[$i - 1][2] = WinGetTitle($aWindows[$i][0]) $aResult[$i - 1][3] = WinGetText($aWindows[$i][0]) $aResult[$i - 1][4] = WinGetProcess($aWindows[$i][0]) $aResult[$i - 1][5] = _ArrayToString(EnumProps($aWindows[$i][0]), ", ", 1) Next _ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|Text|Process|Properties") EndFunc ;==>Example Func EnumProps($hWnd, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'str', "") If @error Or Not $aRet[0] Then $iErr = @error ConsoleWrite("EnumProps Error:" & $iErr & @CRLF) ElseIf $aRet[3] <> "" Then $aProps = StringSplit($aRet[3], ";") EndIf DllCallbackFree($hCb) Return SetError($iErr, 0, $aProps) EndFunc ;==>EnumProps Func _PropEnumProcEx($hWnd, $sProp, $hData, $pStr) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 ; + Null Char If $iSzStr > 1 Then Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) Local $tRetn = DllStructCreate('char[65535]', $pStr) DllStructSetData($tRetn, 1, DllStructGetData($tRetn, 1) & DllStructGetData($tProp, 1) & ";") EndIf Return 1 EndFunc ;==>_PropEnumProcEx ;-------------------------------------------------------------------------------------------------------------- Func EnumProps2($hWnd, $iSzBuffer = 4096, $vDLL = 'user32.dll') ; Create callback function. Local $iErr = 0 Local $sProps Local $aProps[1] = [0] Local $hCb = DllCallbackRegister('_PropEnumProcEx', 'int', 'hwnd;ptr;handle;ptr') Local $tProps = DllStructCreate('int;int;char[' & $iSzBuffer & ']') DllStructSetData($tProps, 1, $iSzBuffer) ;BufferSz DllStructSetData($tProps, 2, $iSzBuffer) ;BufferRemaining ; Call EnumPropsEx Local $aRet = DllCall($vDLL, 'int', 'EnumPropsEx', 'HWND', $hWnd, 'ptr', DllCallbackGetPtr($hCb), 'ptr', DllStructGetPtr($tProps)) If @error Or Not $aRet[0] Then $iErr = @error DllStructSetData($tProps, 2, 0) EndIf DllCallbackFree($hCb) $sProps = DllStructGetData($tProps, 3) If DllStructGetData($tProps, 2) > 0 Then If $sProps <> "" Then $aProps = StringSplit(StringTrimRight($sProps, 1), ";") EndIf Else If Not $iErr Then $iErr = 6 ;buffer overflow Return SetError($iErr, -DllStructGetData($tProps, 2), $aProps) EndIf Return $aProps EndFunc ;==>EnumProps2 Func _PropEnumProcEx2($hWnd, $sProp, $hData, $ptProp) Local $iSzStr = _WinAPI_StringLenA($sProp) + 1 Local $tProp = DllStructCreate('char[' & $iSzStr & ']', $sProp) If $iSzStr > 1 Then Local $sRet = DllStructGetData($tProp, 1) Local $iSzBuffer = DllStructGetData(DllStructCreate('int', $ptProp), 1) Local $tRetn = DllStructCreate('int;int;char[' & $iSzBuffer & ']', $ptProp) DllStructSetData($tRetn, 2, DllStructGetData($tRetn, 2) - $iSzStr) If DllStructGetData($tRetn, 2) > 0 Then DllStructSetData($tRetn, 3, DllStructGetData($tRetn, 3) & $sRet & ";") EndIf EndIf Return 1 EndFunc ;==>_PropEnumProcEx2  
    • 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
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.