Jump to content
Sign in to follow this  
Inververs

[solved] Help with event notifications for IMbnPinManagerEvents interface

Recommended Posts

SafeArray.au3 it`s LarsJ udf. Ifound it in IUIAutomation MS framework automate chrome, FF, IE topic.

#include-once

#cs
Global Const $tagSAFEARRAY = _
    "ushort cDims;"      & _ ; The number of dimensions.
    "ushort fFeatures;"  & _ ; Flags, see below.
    "ulong  cbElements;" & _ ; The size of an array element.
    "ulong  cLocks;"     & _ ; The number of times the array has been locked without a corresponding unlock.
    "ptr    pvData;"     & _ ; The data.
    "ulong  cElements;"  & _ ; The number of elements in the dimension.
    "long   lLbound"         ; The lower bound of the dimension.

; fFeatures flags
Global Const $FADF_AUTO        = 0x0001 ; An array that is allocated on the stack.
Global Const $FADF_STATIC      = 0x0002 ; An array that is statically allocated.
Global Const $FADF_EMBEDDED    = 0x0004 ; An array that is embedded in a structure.
Global Const $FADF_FIXEDSIZE   = 0x0010 ; An array that may not be resized or reallocated.
Global Const $FADF_RECORD      = 0x0020 ; An array that contains records. When set, there will be a pointer to the IRecordInfo interface at negative offset 4 in the array descriptor.
Global Const $FADF_HAVEIID     = 0x0040 ; An array that has an IID identifying interface. When set, there will be a GUID at negative offset 16 in the safe array descriptor. Flag is set only when FADF_DISPATCH or FADF_UNKNOWN is also set.
Global Const $FADF_HAVEVARTYPE = 0x0080 ; An array that has a variant type. The variant type can be retrieved with SafeArrayGetVartype.
Global Const $FADF_BSTR        = 0x0100 ; An array of BSTRs.
Global Const $FADF_UNKNOWN     = 0x0200 ; An array of IUnknown*.
Global Const $FADF_DISPATCH    = 0x0400 ; An array of IDispatch*.
Global Const $FADF_VARIANT     = 0x0800 ; An array of VARIANTs.
Global Const $FADF_RESERVED    = 0xF008 ; Bits reserved for future use.
#ce



Func SafeArrayCreateVector( $sType, $iRows )
    Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
    Local Const $FADF_HAVEIID = 0x0040, $FADF_HAVEVARTYPE = 0x0080, $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200
    Local Const $VT_INT = 22, $VT_INT_PTR = 37

    Local $iVarType, $iFeatures
    Switch $sType
        Case "int"
            $iVarType = $VT_INT
        Case "ptr" ; IUIAutomationCondition interface pointer
            $iVarType = $VT_INT_PTR
            $iFeatures = $FADF_UNKNOWN
            ; $FADF_UNKNOWN must be included in fFeatures in the SafeArray structure.
            ; Otherwise an E_INVALIDARG error will occur when the condition is created.
            If @OSVersion <> "WIN_XP" Then $iFeatures = BitOR( $iFeatures, $FADF_HAVEIID )
            ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE.
        Case "str" ; BSTR (binary string)
            $iVarType = $VT_INT_PTR
            $iFeatures = $FADF_BSTR
        Case Else
            Return SetError(1, 0, 0)
    EndSwitch

    Local $aRet = DllCall( "oleaut32.dll", "ptr", "SafeArrayCreateVector", "int", $iVarType, "long", 0, "ulong", $iRows )
    If @error Then Return SetError(2, 0, 0)
    Local $pSafeArray = $aRet[0]

    Switch $sType
        Case "ptr"
            Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
            Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )
            $fFeatures = BitOR( $fFeatures, $iFeatures )
            If @OSVersion <> "WIN_XP" Then $fFeatures = BitXOR( $fFeatures, $FADF_HAVEVARTYPE )
            ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE.
            DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
        Case "str"
            Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
            Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )
            $fFeatures = BitOR( $fFeatures, $iFeatures )
            DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
    EndSwitch

    Return $pSafeArray
EndFunc

Func SafeArrayGetElement( $pSafeArray, $iIndex, ByRef $vValue )
    Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
    Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200

    Local $fFeatures = DllStructGetData( DllStructCreate( $tagSAFEARRAY, $pSafeArray ), "fFeatures" )

    Local $sType
    Select
        Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN )
            $sType = "ptr*"
        Case Else
            $sType = "int*"
    EndSelect

    Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, 0 )
    If @error Then Return SetError(1, 0, 1)
    $vValue = $aRet[3]

    If BitAND( $fFeatures, $FADF_BSTR ) Then
        $vValue = SysReadString( $vValue )
        If @error Then Return SetError(2, 0, 1)
    EndIf

    Return $aRet[0]
EndFunc

Func SafeArrayPutElement( $pSafeArray, $iIndex, $vValue )
    Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
    Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200

    Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
    Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )

    Local $sType
    Select
        Case BitAND( $fFeatures, $FADF_BSTR )
            $sType = "ptr*"
            DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_BSTR )
            ; This is a workaround. String is not inserted if $fFeatures includes $FADF_BSTR.
            $vValue = SysAllocString( $vValue )
            If @error Then Return SetError(1, 0, 1)
        Case BitAND( $fFeatures, $FADF_UNKNOWN )
            $sType = "ptr*"
            DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_UNKNOWN )
            ; This is a workaround. The DllCall crashes if $fFeatures includes $FADF_UNKNOWN.
        Case Else
            $sType = "int*"
    EndSelect

    Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayPutElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, $vValue )
    If @error Then Return SetError(2, 0, 1)

    Select
        Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN )
            DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
            ; This will undo the workaround.
    EndSelect

    Return $aRet[0]
EndFunc

Func SafeArrayGetUBound( $pSafeArray, ByRef $iUBound )
    Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetUBound", "ptr", $pSafeArray, "uint", 1, "long*", 0 )
    If @error Then Return SetError(1, 0, 1)
    $iUBound = $aRet[3]
    Return $aRet[0]
EndFunc

Func SafeArrayDestroy( $pSafeArray )
    Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayDestroy", "ptr", $pSafeArray )
    If @error Then Return SetError(1, 0, 1)
    Return $aRet[0]
EndFunc



; BSTR functions
; Copied and slightly modified from AutoItObject.au3 by the AutoItObject-Team

Func SysAllocString( $str )
    Local $aRet = DllCall( "oleaut32.dll", "ptr", "SysAllocString", "wstr", $str )
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[0]
EndFunc

Func SysFreeString( $pBSTR )
    If Not $pBSTR Then Return SetError(1, 0, 0)
    DllCall( "oleaut32.dll", "none", "SysFreeString", "ptr", $pBSTR )
    If @error Then Return SetError(2, 0, 0)
EndFunc

Func SysReadString( $pBSTR, $iLen = -1 )
    If Not $pBSTR Then Return SetError(1, 0, "")
    If $iLen < 1 Then $iLen = SysStringLen( $pBSTR )
    If $iLen < 1 Then Return SetError(2, 0, "")
    Return DllStructGetData( DllStructCreate( "wchar[" & $iLen & "]", $pBSTR ), 1 )
EndFunc

Func SysStringLen( $pBSTR )
    If Not $pBSTR Then Return SetError(1, 0, 0)
    Local $aRet = DllCall( "oleaut32.dll", "uint", "SysStringLen", "ptr", $pBSTR )
    If @error Then Return SetError(2, 0, 0)
    Return $aRet[0]
EndFunc

 

Share this post


Link to post
Share on other sites

Actually, msdn documents that struct can be defined as parameter. It's also documented how to handle it. For example on x64 it's like this:

(...) strings are never passed by immediate value but rather a pointer is passed to memory allocated by the caller. Structs/unions of size 8, 16, 32, or 64 bits (...) are passed as if they were integers of the same size. Structs/unions other than these sizes are passed as a pointer to memory allocated by the caller (...)


♡♡♡

.

eMyvnE

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By tarretarretarre
      About AutoIt-API-WS
      AutoIt-API-WS is a light weight web server with expressive syntax, with the sole purpose of wrapping your existing AutoIt app with little to no effort.
      With AutoIt-API-WS you can send and receive data between any application or framework, as long they can handle HTTP requests, which is an industry standard today.
      Like my other communcations UDF AutoIt-Socket-IO AutoIt-API-WS is heavily inspired from the big boys, but this time its Laravel and Ruby on Rails.
      Features Highlights
      No external or internal dependencies required RESTful mindset when designed Expressive syntax Small codebase Heavy use of Michelsofts Dictionary object Limitations
      Not complient with any RFC, so something important could be missing. Time will tell! One persons slow loris attack will kill the process forever. Example of implemetnation (With screenshots)
      This is a basic cRud operation with the RESTful mindset in use.
      #include "API.au3" #include <Array.au3> _API_MGR_SetName("My APP DB adapter") _API_MGR_SetVer("1.0 BETA") _API_MGR_SetDescription("This adapter allows you to get this n that") _API_MGR_Init(3000) _API_MGR_ROUTER_GET('/users', CB_GetUsers, 'string sortBy', 'Get all users, sortBy can be either asc or desc. asc is default') _API_MGR_ROUTER_GET('/users/{id}', CB_GetUsersById, 'int id*', 'Get user by id') While _API_MGR_ROUTER_HANDLE() WEnd Func DB_GetUsers() Local $userA = ObjCreate("Scripting.Dictionary") Local $userB = ObjCreate("Scripting.Dictionary") $userA.add('id', 1) $userA.add('name', 'TarreTarreTarre') $userA.add('age', 27) $userB.add('id', 2) $userB.add('name', @UserName) $userB.add('age', 22) Local $aRet = [$userA, $userB] Return $aRet EndFunc Func CB_GetUsers(Const $oRequest) Local $aUsers = DB_GetUsers() If $oRequest.exists('sortBy') Then Switch $oRequest.item('sortBy') Case Default Case 'asc' Case 'desc' _ArrayReverse($aUsers) EndSwitch EndIf Return $aUsers EndFunc Func CB_GetUsersById(Const $oRequest) Local Const $aUsers = DB_GetUsers() Local $foundUser = Null For $i = 0 To UBound($aUsers) -1 Local $curUser = $aUsers[$i] If $curUser.item('id') == $oRequest.item('#id') Then $foundUser = $curUser ExitLoop EndIf Next If Not IsObj($foundUser) Then Return _API_RES_NotFound(StringFormat("Could not find user with ID %d", $oRequest.item('#id'))) EndIf return $foundUser EndFunc When you visit http://localhost:3000 you are greeted with this pleasent view that will show you all your registred routes and some extra info you have provided.

      When you visit http://localhost:3000/users the UDF will return the array of objects as Json
       
      And here is an example of http://localhost:3000/users/1

       
      More examples can be found here
       
       
      Autoit-API-WS-1.0.0-beta.zip (OLD!)
      Autoit-API-WS-1.0.1-beta.zip (NEWEST 2020-06-29)
    • By nacerbaaziz
      goodmorning autoit team
      today am comming with some winhttp problems, i hope that you can help me to solve them.
      the first problem
      is when opening a request
      my forums api allow me to delete any post using the api key
      all functions work, i mean post / get
      but when i tried to use the delete verb it's gave me an html 404 error
      here is what am tried
      #include "WinHttp.au3" ; Open needed handles Global $hOpen = _WinHttpOpen() Global $hConnect = _WinHttpConnect($hOpen, "xxxxxxxx.com") ; Specify the reguest: Global $hRequest = _WinHttpOpenRequest($hConnect, "Delete", "/vb/Api/posts/10447/?hard_delete=true", default, default) _WinHttpAddRequestHeaders($hRequest, "XF-Api-Key:xxxxx") _WinHttpAddRequestHeaders($hRequest, "XF-Api-User:xxxxx") ; Send request _WinHttpSendRequest($hRequest) ; Wait for the response _WinHttpReceiveResponse($hRequest) Global $sHeader = 0, $sReturned = 0 ; If there is data available... If _WinHttpQueryDataAvailable($hRequest) Then $sHeader = _WinHttpQueryHeaders($hRequest, $WINHTTP_QUERY_CONTENT_DISPOSITION) ;Or maybe: ; $sHeader = _WinHttpQueryHeaders($hRequest, BitOR($WINHTTP_QUERY_RAW_HEADERS_CRLF, $WINHTTP_QUERY_CUSTOM), "Content-Disposition") Do $sReturned &= _WinHttpReadData($hRequest) Until @error msgBox(64, "", $sReturned) endIf ; Close handles _WinHttpCloseHandle($hRequest) _WinHttpCloseHandle($hConnect) _WinHttpCloseHandle($hOpen)  
      and here is the error message
      <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>403 Forbidden</title> </head><body> <h1>Forbidden</h1> <p>You don't have permission to access /vb/Api/posts/10447/ on this server.<br /> </p> </body></html>  
      i hope you can help me 
      thanks in advance
    • By argumentum
      I can TCP/IP in AutoIt, hence, make a HTTP deamon. Now, how can I HTTPS to use SSL !??
      Well, Apache has this "mod_proxy.so" module that can let me have SSL and what not is in Apache.
      All that is needed is to tell Apache what I wanna do by editing httpd.conf .
      # Implements a proxy/gateway for Apache. # 1. Open /Applications/XAMPP/etc/httpd.conf # 2. Enable the following Modules by removing the # at the front of the line. # - LoadModule rewrite_module modules/mod_rewrite.so # - LoadModule proxy_module modules/mod_proxy.so # - LoadModule proxy_http_module modules/mod_proxy_http.so # # 3. Copy and Paste below to the bottom of httpd.conf # <IfModule mod_proxy.c> ProxyRequests On <Proxy *> Order deny,allow Allow from all </Proxy> ProxyVia Off ProxyPreserveHost Off ProxyPass /home/ http://127.0.0.1:84/home/ ProxyPassReverse /home/ http://127.0.0.1:84/home/ SetEnv proxy-nokeepalive 1 # ..since we are not using "keep-alive", we are using "close" </IfModule> ...et voila  
      I'm using XAMPP ( https://www.apachefriends.org/download.html )
      and this is my solution to avoid coding in PHP, as I feel more comfortable coding in AutoIt.
      A "muli-thread or concurrency" can be done by forking the socket ( https://www.autoitscript.com/forum/topic/199177-fork-udf-ish/ )
      but responses are under 20 ms., so I feel fine with a single thread.
      I modified an example ( attached below ), so can try out the concept.
      PS: I am not an Apache guru. I just discovered this and it opens a world of possibilities. In my case, I'm thinking of an API to query SQLite 
      PS2: I'm not gonna make Poll but do click like if you do  
       
      201673-json-http-post-serverlistener.au3
    • By MichaelSDeVries
      Has anyone successfully developed  integration with the E*TRADE API in AutoIt?


       
      If so, then would you be willing and able to share some of your AutoIt code to do so with me? and/or help me successfully develop an AutoIt interface with the E*TRADE API?

       
      Please also Reply at: http://blog.thevcf.com/forums/topic/etrade-api/#post-4032

       
      Thank You and Have a Great Day!
      - Michael S. DeVries
    • By rcmaehl
      Hi all, 

      Recently my work swapped from Cisco CTIOS to Finesse. This completely threw me off as I had been automating the Win32 application and I had never done IUIAutomation before. As such I've been messing around with the API and will be adding code as I figure it out. While I do have Supervisor access, I will likely not be adding functions for those features yet.
      Currently Available Functions:
      User API - Query and Set User Info
      Dialog API - Query and Set Call and other Dialog Info
      Queue API - Query Assigned Queues
      Team API - Query Users in a Team


      Changelog:
       
      Download:
       
×
×
  • Create New...