Sign in to follow this  
Followers 0
jaberwacky

Trying to make a change to AutoItObject. Any hints?

1 post in this topic

#1 ·  Posted (edited)

Hi.  Decided to put this question here because the description covers "General coding talk. Scripting, programming, C++, etc."

So, I'm trying to alter AutoItObject to accept references to functions rather than just strings.  For example:

$this.AddMethod("MyMethod", "_my_method") 
to this-->
$this.AddMethod("MyMethod", _my_method)

And so I found this class:

class AutoItElement
{
    public:
      AutoItElement(void);
      AutoItElement(wchar_t* name,VARIANT*);
      ~AutoItElement(void);
    
      enum TYPE
      {
        NOTHING, 
        METHOD,
        PROPERTY
      };
      
      TYPE GetType() const;
      
      void SetType(TYPE new_type);
      
      enum SCOPE
      {
        PUBLIC,
        READONLY,
        PRIVATE
      };
      
      SCOPE GetScope() const;
      
      void SetScope(SCOPE new_scope);
      
      void SetData(LPCWSTR);
      
      void SetData(VARIANT*);
      
      VARIANT* GetData();
      
      wchar_t* GetName();
      
      void SetName(wchar_t*);
      
    private:
      wchar_t* name;

      VARIANT data;

      TYPE type;

      SCOPE scope;
};

Which looks to me to have an overloaded SetData accepting a pointer to a type VARIANT.

This leads me to wonder if all I would need to do is to change these functions:

void AutoItObject::AddMethod(wchar_t* method, wchar_t* value, AutoItElement::SCOPE new_scope)
{
    AutoItElement *elem = new AutoItElement;
    elem->SetType(AutoItElement::METHOD);
    elem->SetScope(new_scope);
    elem->SetName(method);
    elem->SetData(value);
    this->AddMember(elem);
}

to this -->

void AutoItObject::AddMethod(wchar_t* method, <something>* value, AutoItElement::SCOPE new_scope)
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
    AutoItElement *elem = new AutoItElement;
    elem->SetType(AutoItElement::METHOD);
    elem->SetScope(new_scope);
    elem->SetName(method);
    elem->SetData(value);
    this->AddMember(elem);
}

And this:

Func _AutoItObject_AddMethod(ByRef $oObject, $sName, $sAutoItFunc, $fPrivate = False)
    ; Author: Prog@ndy
    If Not IsObj($oObject) Then Return SetError(2, 0, 0)
    
    Local Const $iFlags = $fPrivate ? $ELSCOPE_PRIVATE : 0
 
    DllCall($ghAutoItObjectDLL, "none", "AddMethod", "idispatch", $oObject, "wstr", $sName, "wstr", $sAutoItFunc, 'dword', $iFlags)
    
    If @error Then Return SetError(1, @error, 0)
    
    Return True
EndFunc   ;==>_AutoItObject_AddMethod

To this -->

Func _AutoItObject_AddMethod(ByRef $oObject, $sName, $sAutoItFunc, $fPrivate = False)
    ; Author: Prog@ndy
    If Not IsObj($oObject) Then Return SetError(2, 0, 0)
    
    Local Const $iFlags = $fPrivate ? $ELSCOPE_PRIVATE : 0
    
    DllCall($ghAutoItObjectDLL, "none", "AddMethod", "idispatch", $oObject, "wstr", $sName, "ptr", $sAutoItFunc, 'dword', $iFlags)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^ 
    If @error Then Return SetError(1, @error, 0)
    
    Return True
EndFunc   ;==>_AutoItObject_AddMethod

Or does the rabbit hole go deeper than I could ever imagine?

Edited by jaberwacky

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