Jump to content

Creating COM objects without a need of DLL's


ptrex
 Share

Recommended Posts

@sohfeyr

I can't give more details for now, because I already spent way to much time this little monster so far.

-> Days of reading testing and investigating.

I hope to spent more time on the WSC - COM thing over the weekend, and keep you all updated.

regards,

ptrex

Link to comment
Share on other sites

@sohfeyr, Uten

This is an example from a callback scenario.

Save this as AU3_Callback_Test.vbs. Don't forget to change the path of the AU3 script if needed.

Dim WshShell, oExec, Output, Result
Set WshShell = CreateObject("WScript.Shell")

CMD = "C:\Progra~1\AutoIt3\AutoIt3.exe /AutoIt3ExecuteScript C:\_\Apps\AutoIT3\COM\VBScript_COM\Test_Financial.au3"
Set oExec = WshShell.Exec(CMD)

Output = oExec.StdOut.ReadAll()
Result = cdbl(Output) 

WScript.Echo Output &" Returned from AU3" & vbCR & vbCR & Result + 100000 _
& vbCR & vbCR & " Added 100000 to the AU3 return value"

This is the AU3 script that returns to value to VBS for further handling.

;===============================================================================
;
; Description:      Loan Amortization
; Parameter(s):     $A=Principal amount of the loan
;                   $B=Annual interest rate. Input format for 11% is 11, not 0.11
;                   $C=Total number of periodic payments
; Requirement:      None
; Return Value(s):  On Success - $E= Periodic payments of the loan
;                                    And sets @ERROR = 0
;                   On Failure - Returns 0 value, and sets @ERROR = 1
; User CallTip:     _Loan_Amortization( ???
; Author(s):        ptrex
; Note(s):          :
;
;===============================================================================


ConsoleWrite(StringReplace(Round(_Loan_Amortization(10000,4,24),3),".",","))

Func _Loan_Amortization($A,$B,$C)
    Local $D, $E
    If BitAND(IsNumber($A),$A>0) And BitAND(IsNumber($B),$B>0,$B<=100) And BitAND(IsInt($C),$C>0) Then ; Modified Input check
        $E=$B/100;
        $D=$A*($E/12)/(1-1/(EXP($C*LOG(1+$E/12))))
            SetError(0)
            Return $D
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc ;==>_Loan_Amortization

Run the VBS and you'll see that the AU3 returned a value of 434,249

The amount is returned to VBS and I added 100.000 to it.

Beaware where I live we use a comma as a decimal separater. You need to change the AU3 script if needed in the other case.

Later on I'll show you all a COM example.

I hope this can alread help you all get going.

regards

ptrex

Link to comment
Share on other sites

@sohfeyr, Uten

This is an example from a callback scenario.

...

Later on I'll show you all a COM example.

I hope this can alread help you all get going.

regards

ptrex

I don't think we're communicating. All you showed in this example is a practical use of the StdOut stream and the command line parameters, which have been available all along. I thought you were talking about being able to call individual Autoit functions from other languages, not simply run entire scripts. When you get a chance, would you please clarify what your past couple of examples have to do with what you are trying to accomplish?

The limitation of what you posted above is that it will run a new process every time you call that function. I don't dispute it has the desired effect, but it is hardly the same thing? If you were to put a call like that in a loop, you could seriously slow down your system! By contrast, if you were able to preload the autoit file somehow and make calls to it, you wouldn't have all the startup and shutdown time. (At least, that's what happened in my experiment...)

Aw heck, you've been working at it a long time... I'll just sit back and watch to see what you come up with. The COM creation is still a huge deal, even if putting a COM-friendly interface on a UDF turns out to be impractical.

Edited by sohfeyr
Link to comment
Share on other sites

Hello!

I'm OK with Sohfeyr: there are no real communication with the .au3 (COM?) script.

And, for launch (AutoIt3 /AutoIt3ExecuteLine), you can let down WSC, and use diretly (WScript.Shell).

I'm sorry, because the need exist.

& thanks for the exploration of this way.

...and sorry for my bad english

Edited by Michel Claveau
Link to comment
Share on other sites

@Michel Claveau

you can let down WSC, and use diretly (WScript.Shell).

If you can show me how to make COM object with using only WScript.Shell, I am interested to see that !!

Using only Wscript and AU3 is missing the point of this threat "Creating COM objects without a need of DLL's" :P

Au Revoir and see you around.

regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@sohfeyr

Again the main objective of this thread is to create "COM objects without a need of DLL's". as explained by examples in the first post.

I don't think we're communicating.

I don' t know what you define under communication by in my perception there is communication :

1. A COM object call the AU2COM server (see examples in the first post)

2. The AU2COM server calls an AU3 script, by means of VBScript. (See last example provided)

3. The values returned by AU3 are retrieved by the AU2COM server (See last example provided)

4. These returned values can be returned by the COM object of step 1. (No example given yet)

It is not because I didn't show you the whole picture, that there is no communication.

Use you immagination a bit to see the applicability of this.

I must say might be a "pseudo" communication. But saying there is none, is a BIG difference. :P

Let's see with what comes next, but at the moment I am working on a JAVA2AU3 using WSC-COM thing.

regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@sohfeyr

Again the main objective of this thread is to create "COM objects without a need of DLL's". as explained by examples in the first post.

I don' t know what you define under communication by in my perception there is communication :

1. A COM object call the AU2COM server (see examples in the first post)

2. The AU2COM server calls an AU3 script, by means of VBScript. (See last example provided)

3. The values returned by AU3 are retrieved by the AU2COM server (See last example provided)

4. These returned values can be returned by the COM object of step 1. (No example given yet)

It is not because I didn't show you the whole picture, that there is no communication.

Use you immagination a bit to see the applicability of this.

I must say might be a "pseudo" communication. But saying there is none, is a BIG difference. :P

Ouch. Ok, I deserved that. Serves me right for posting while tired. #2-3 didn't take the form I expected, so I didn't recognize it as what you had described.

Link to comment
Share on other sites

Hi @ptrex,

I have been playing a bit more. Your enthusiastic post about how we could integrate au3 code with other COM loading applications made me think you had solved the communication between the script engine and the WSC host. Although communication through stdio is possible I don't think communicating through stdio is a solution in the long run. Basically because the code in both ends will add up and make it unpractical. But it's a start, so kudos do you for trying. Maybe communicating through environmental variables or the registry are areas that needs to be explored to.

To ease my own testing in SciTE I have created a wsc.properties file. I just cant stand black and white code. Took me some time to understand how to get it right so if anyone else needs it it's up for grabs.

Keep it up @ptrex, it is interesting to see where this will lead us..:P

Link to comment
Share on other sites

@Uten

Thanks for you contribution !!

The "stdi/o" is the only way to communicate so far.

What else did I test (without success yet) :

INPUT :

I tried to use the $CMDLINE input to communicate with, but no success yet. Nevertheless it should work with compiled .EXE's.

Thin intention was to create COM Object with parameter values. These values should be passed to the COM server which put the VALUES in a variable.

Then the VARS can be put forward to the /AUTOITSCRIPT command, including the VARIABLES.

This way we could build a Library of functions in AU3, compile it and access it trough the $CMDLINE (max. up to 64 parameters).

OUTPUT :

"stdout" successfull.

If we can solbe the input side this could mean a breakthrough.

I don't have much time anymore to spend on this for now, so it will have to rest a while.

Anyone else who whants to give it a try, let me know.

regards,

ptrex

Link to comment
Share on other sites

Link to comment
Share on other sites

Thanks for your work so fare @ptrex. Sometimes it's just annoyingly time consuming to figure out workarounds.

I newer did care much for WSH, so my limited knowledge in using it is a showstoper for me.

Anyhow I seem to remember that we can create classes in VBScript (if anyone has a simple sample to share pleas do). If I understand it correctly the WSC component is a class/object in it selfe and should have a constructor (or similar) called as it is loaded and a destructor method called as it is destroyed. We should/could load and terminate our autoit exe in those events. Then use a communication protocol (XML-RPC light) between the wsc component and the autoit exe through stdio,IP,pipe or similar. The protocol and handler could be implemented as UDF's (in VBScript or JScript) to ease implementations of wsc/autoit components.

The big question is: Is it worth the trouble. Or is it better just to use the other script engines and AutoItX.dll? You don't get the gui part, but there are gui dll's for VBScript out there if I recall right.

But that's just my thoughts at the moment..:)

Link to comment
Share on other sites

@Uten

Thanks for your input so far.

Is it worth the trouble.

I think yes of cource it should be worthwhile doing.

But of cource my opinion is not objective since I posted this thread. :">

The main advantages are posted in the first post.

I would definitely use it for is to translate the SQLite UDF to a COM oriented UDF. Because I hate the syntax as it is know.

I am spoiled by the SQLiteX COM DLL, So I would love to see this comming up in AU3.

All of these jobs are hard to handle with the normal AutoItX.dll. Once we get it going we have UDF the can be reused in Other COM Compliant apps.

So that' s the major advantage of it to me.

Anyhow I am not familiar with (XML-RPC light) but it sounds a good approach to me.

So let me know if I can be of any help so far. I will be doing tests in the background based on the old approach in the meantime.

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

Is it worth the trouble

Yes, yes, a thousand times YES!

The feature found in other languages that I miss most in Autoit is encapsulation. The UDF set I'd like to encapsulate most as a COM object would be the Auto3Lib, and after that the extant GUI UDFs.

Even if it isn't much of a performance benefit, if it leads to cleaner (and therefore more maintainable) code, it would be totally worth it - as long as there isn't some substantial performance hit, like you get when running a udf "engine" in a seperate process.

Link to comment
Share on other sites

@All who are still interested

Here I will show you the full picture, with the working callback example.

Save this as Financial.wsc

Don't forget to register, and change the path of the Test_Financial.au3 script location !!

<?xml version="1.0"?>
<component>
<registration
 description="Loan Amortization"
 progid="AU2COM_Financial.WSC" 
version="1.00" 
classid="{7428c732-9472-422e-9878-bdca8433db0e}"
>
</registration>
<public>
 <property name="Principle_Amount" internalname="iNum1"/>
 <property name="Interest" internalname="iNum2"/>
 <property name="Per_Payments" internalname="iNum3"/>

<method name="LoanAmortization">
 <PARAMETER name="iValue1"/>
 <PARAMETER name="iValue2"/>
 <PARAMETER name="iValue3"/>
</method>

<method name="Amortization">
</method>
</public> 

&lt;script language="VBScript"> 
<![CDATA[ 

Dim iNum1, iNum2, iNum3
Dim WshShell, oExec, Output

sub LoanAmortization(iValue1, iValue2, iValue3)
 iNum1=iValue1
 iNum2=iValue2
 iNum3=iValue3

 Cmd="C:\Progra~1\AutoIt3\AutoIt3.exe /AutoIt3ExecuteScript C:\_\Apps\AutoIT3\COM\VBScript_COM\Test_Financial.au3"

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec(CMD)

oExec.StdIn.Write _
iNum1 & "|" & iNum2 & "|" & iNum3 & "|" & _
"Test"

'oExec.StdIn.WriteBlankLines(3)
oExec.StdIn.close
End sub 

Function Amortization()
 Output = oExec.StdOut.ReadAll()
 Amortization = Output
End function

]]> 
</script>
</component>

This is the AU3 Loan Amortization UDF save as Test_Financial.au3

;===============================================================================
;
; Description:      Loan Amortization
; Parameter(s):     $A=Principal amount of the loan
;                   $B=Annual interest rate. Input format for 11% is 11, not 0.11
;                   $C=Total number of periodic payments
; Requirement:      None
; Return Value(s):  On Success - $E= Periodic payments of the loan
;                                    And sets @ERROR = 0
;                   On Failure - Returns 0 value, and sets @ERROR = 1
; User CallTip:     _Loan_Amortization( ???
; Author(s):        ptrex
; Note(s):          :
;
;===============================================================================
Dim $i
; ConsoleRead(0,"Peek") returnes the number of Characters
MsgBox(0,"# of Chr. read", "Input from AU2COM = " & ConsoleRead(0,"Peek") & " Char")

$i = StringSplit(ConsoleRead(),"|") 
ConsoleWrite(StringReplace(Round(_Loan_Amortization(number($i[1]),number($i[2]),number($i[3])),3),".",",")) 

Func _Loan_Amortization($A,$B,$C)
    Local $D, $E
    If BitAND(IsNumber($A),$A>0) And BitAND(IsNumber($B),$B>0,$B<=100) And BitAND(IsInt($C),$C>0) Then ; Modified Input check
        $E=$B/100;
        $D=$A*($E/12)/(1-1/(EXP($C*LOG(1+$E/12))))
            SetError(0)
            Return $D
    Else
        SetError(1)
        Return 0
    EndIf
EndFunc ;==>_Loan_Amortization

_Test($i)

Func _Test($i)
MsgBox(0,"Feedback", "From AutoIT : " & $i[4])
Endfunc
oÝ÷ Ù:ò¶!jx¶§¶)íz·¬¶éz¸¨u©Ý±ç°«aj^Æ®¶­sc²æFƦR4ôÒW'&÷"æFÆW"¢b33c¶ô×W'&÷"Òö&¤WfVçBgV÷C´WFôBäW'&÷"gV÷C²ÂgV÷C´×W'$gVæ2gV÷C²¢b33c¶ö&¥u42Òö&¤7&VFRgV÷C´S$4ôÕôfææ6Âåu42gV÷C² ¤b4ö&¢b33c¶ö&¥u42FVà¢b33c´ÆöâÒb33c¶ö&¥u42äÆöäÖ÷'F¦FöâÃ2Ã#B²&æ6ÆRÖ÷VçBÂçFW&W7BÂW&ö@ ¤×6t&÷ÂgV÷C´6ÆÆ&6²S$4ôÒgV÷C²ÂgV÷Cµ÷W"Ö÷'F¦FöâW"ÖöçF2¢gV÷C²fײ5"fײb33c¶ö&¥u42äÖ÷'F¦FöâfײgV÷C²b33c²ògV÷C²²&W7VÇB&WGW&æVBg&öÒS$4ôÐ ¤VÇ6R ×6t&÷ÂgV÷C´W'&÷"gV÷C²ÂgV÷C´æòvööBö&¦V7BFV6Æ&VBgV÷C²¤VæD` ¤gVæ2×W'$gVæ2¢b33c´WçVÖ&W#ÖWb33c¶ô×W'&÷"æçVÖ&W"â×6v&÷ÂgV÷C´4ôÒFW7BgV÷C²ÂgV÷CµvRçFW&6WFVB4ôÒW'&÷"b333²gV÷C²fײ5$Äbfײ5$Äbfײð gV÷C¶W'"æFW67&Föâ3¢gV÷C²fײD"fײb33c¶ô×W'&÷"æFW67&Föâfײ5$Äbfײð gV÷C¶W'"çvæFW67&Föã¢gV÷C²fײD"fײb33c¶ô×W'&÷"çvæFW67&Föâfײ5$Äbfײð gV÷C¶W'"æçVÖ&W"3¢gV÷C²fײD"fײb33c´WçVÖ&W"fײ5$Äbfײð gV÷C¶W'"æÆ7FFÆÆW'&÷"3¢gV÷C²fײD"fײb33c¶ô×W'&÷"æÆ7FFÆÆW'&÷"fײ5$Äbfײð gV÷C¶W'"ç67&FÆæR3¢gV÷C²fײD"fײb33c¶ô×W'&÷"ç67&FÆæRfײ5$Äbfײð gV÷C¶W'"ç6÷W&6R3¢gV÷C²fײD"fײb33c¶ô×W'&÷"ç6÷W&6Rfײ5$Äbfײð gV÷C¶W'"æVÇfÆR3¢gV÷C²fײD"fײb33c¶ô×W'&÷"æVÇfÆRfײ5$Äbfײð gV÷C¶W'"æVÇ6öçFWB3¢gV÷C²fײD"fײb33c¶ô×W'&÷"æVÇ6öçFWBð ¢6WDW'&÷"²Fò6V6²f÷"gFW"F2gVæ7Föâ&WGW&ç0¤VæFgVæ

Enjoy !!

Try to sent in your examples !!

Regards,

ptrex

Edited by ptrex
Link to comment
Share on other sites

@all

I did show how the COM server interacts with the COM objects in an AU3 script. Calling UDF's from an other AU3 script and returning results to the COM objects.

Everything works fine as you can test through the example given in the previous post.

At the moment I am looking for a solution to call one Function() in an AU3 file or Compiled EXE.

I have been playing around with "CALL" and "EXECUTE", but no success.

Any hints are welcome.

Thanks

Link to comment
Share on other sites

WOW!

ptrex, this is simply amazing!!

Now if only we could figure out how to use <script language="AutoIt"> .....

The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Link to comment
Share on other sites

@theguy0000

Thanks for your feedback

Now if only we could figure out how to use <script language="AutoIt"> .....

I guess it won't be happening since it depends on the Devs to make it happen.

But anyhow the example in my post 55 shows that the workaround does work too.

regards,

ptrex

Link to comment
Share on other sites

  • 7 months later...

Hi,

i'd like to try this, but the "demo.sc" script in first post won't register; how has anyone tested this? ["no matching tag"]

Best, randall

I think that the problem is to do with the forum display. I actually know nothing about wsc or sct yet, but I think the

&lt is the HTML code used for the less than sign which should be displayed as less than but it isn't. Hope that makes sense. So you just need to edit the script and replace all the '&lt;' with '<'.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...