trancexx Posted May 17, 2011 Author Share Posted May 17, 2011 I am new in objects. can you please post a one example. It's really trivial. This maybe: expandcollapse popup#include <AutoitObject.au3> Opt("MustDeclareVars", 1) ; Object moniker Global Const $sObjIdentifier = "DigisoulExampleIPC.Unique" ; Error monitoring Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc") Func _ErrFunc() ;~ ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF) EndFunc ; Initialize AutoItObject _AutoItObject_StartUp() ; Create object Global $oObject = _IPCObject($sObjIdentifier) ; GUI for this demonstration Global $hGui = GUICreate("AutoItObject IPC Example", 500, 500) Global $hButtonSet = GUICtrlCreateButton("< Set shared IPCData >", 300, 100, 150, 30) Global $hButtonRead = GUICtrlCreateButton("> Read shared IPCData <", 300, 350, 150, 30) Global $hEditSet = GUICtrlCreateEdit("", 20, 20, 250, 200) Global $hEditRead = GUICtrlCreateEdit("", 20, 270, 250, 200) GUISetState() While 1 Switch GUIGetMsg() Case -3 Exit Case $hButtonSet $oObject.IPCData = GUICtrlRead($hEditSet) Case $hButtonRead GUICtrlSetData($hEditRead, $oObject.IPCData) EndSwitch WEnd ;**************************************************************** ;**************************************************************** Func _IPCObject($sID) ; First try to get object from ROT Local $oObj = ObjGet($sID) If IsObj($oObj) Then Return $oObj ; OK! ; If that failed then create object from scratch $oObj = _MakeIPCObject() ; Register (publish) created object _AutoItObject_RegisterObject($oObj, $sID) Return $oObj ; return it EndFunc ; Define object Func _MakeIPCObject() Local $oClassObject = _AutoItObject_Class() $oClassObject.AddProperty("IPCData") ; adding just one property Return $oClassObject.Object ; here's the object EndFunc ;==>_SomeObject ;**************************************************************** ;**************************************************************** Run as many instances of that script, they will all share the same variable (object property). Share as have read/write access. First script that creates the object owns it (server). When that script exits there is object no more. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
isjones Posted May 17, 2011 Share Posted May 17, 2011 This likely a no-brainer but forgive me please for getting carried away. I very recently started learning Javascript and have investigated jsc.exe. I am impressed by this application of Autoit (and , indeed I should emphasise AutoIt) and would like to create (in the future) standalone exes (if possible) either in a language like javascript or in Autoit (or both (oh, get to the point man!) that make muliti-script language usage. How would I accomplish this? The key being to start the server and kill the server on exit. TIA Link to comment Share on other sites More sharing options...
trancexx Posted May 17, 2011 Author Share Posted May 17, 2011 (edited) This likely a no-brainer but forgive me please for getting carried away. I very recently started learning Javascript and have investigated jsc.exe. I am impressed by this application of Autoit (and , indeed I should emphasise AutoIt) and would like to create (in the future) standalone exes (if possible) either in a language like javascript or in Autoit (or both (oh, get to the point man!) that make muliti-script language usage. How would I accomplish this? The key being to start the server and kill the server on exit.TIAStart server from other script? Is that it?If it is then if you want it to work on systems without AutoIt installed, compile the server and add function to run it from that other (vbs, js, whatever) script. If you don't know how to Run executables using those languages then... learn. Edited May 17, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
isjones Posted May 18, 2011 Share Posted May 18, 2011 Hi trancexx, "Line:6, Column:1, Error:(null), Code:800401E4, Source:(null)" 3. Set WshShell = WScript.CreateObject("WScript.Shell") 4. WshShell.Run "h:\AutoItServer.exe" 5. 6. Set oAutoIt = GetObject("AutoIt.Application") ' the magic Falls over for me at Line 6.(?) Does there need to be a pause or return code from WshShell.Run? Link to comment Share on other sites More sharing options...
trancexx Posted May 18, 2011 Author Share Posted May 18, 2011 (edited) Hi trancexx, "Line:6, Column:1, Error:(null), Code:800401E4, Source:(null)" 3. Set WshShell = WScript.CreateObject("WScript.Shell") 4. WshShell.Run "h:\AutoItServer.exe" 5. 6. Set oAutoIt = GetObject("AutoIt.Application") ' the magic Falls over for me at Line 6.(?) Does there need to be a pause or return code from WshShell.Run? Yes, you need to give AutoIt enough time to initialize, start interpreting process and all other script stuff. Set oAutoIt = GetROTObject("AutoItServer.exe", "AutoIt.Application") '... Function GetROTObject(sServer, sCLSID) iTimeout = 3000 ' default timeout in ms On Error Resume Next Set oObject = GetObject(sCLSID) If Not IsObject(oObject) Then Set oWShell = WScript.CreateObject("WScript.Shell") oWShell.Run """" & sServer & """ /StartServer" For i = 0 To iTimeout/10 Set oObject = GetObject(sCLSID) If IsObject(oObject) Then Exit For Wscript.Sleep(10) Next If Not IsObject(oObject) Then oWShell.Run "taskkill /f /im " & """" & sServer & """", 0, True End If Set GetROTObject = oObject End Function Edited May 18, 2011 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 23, 2011 Share Posted May 23, 2011 Why does this work: Global $sMyCLSID = "AutoIt.Application" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) But not this? Global $sMyCLSID = "ShiftERZipServer.Application" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) This works so it's not about the length Global $sMyCLSID = "AutoItjhhhhhhhhhhhhhhhhhhhhhhhh.Applicationggggggggggggggggg" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted May 23, 2011 Author Share Posted May 23, 2011 Why does this work: Global $sMyCLSID = "AutoIt.Application" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) But not this? Global $sMyCLSID = "ShiftERZipServer.Application" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) This works so it's not about the length Global $sMyCLSID = "AutoItjhhhhhhhhhhhhhhhhhhhhhhhh.Applicationggggggggggggggggg" Global $hObj = _AutoItObject_RegisterObject($oObject, $sMyCLSID) ConsoleWrite($hObj & @CRLF) Are you sure there isn't server already running? Check that. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 23, 2011 Share Posted May 23, 2011 Are you sure there isn't server already running? Check that.You are right, the server was already running. Can't understand how I missed it, I actually had Task Manager opened when working on it! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
trancexx Posted May 23, 2011 Author Share Posted May 23, 2011 You are right, the server was already running. Can't understand how I missed it, I actually had Task Manager opened when working on it! I just saw your (new?) member title or whatever that's called. Funny guy. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted May 23, 2011 Share Posted May 23, 2011 I just saw your (new?) member title or whatever that's called. Funny guy.I've been "uncloaked" for almost two months now, I think you need to recalibrate your sensors! .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
chinafla Posted May 24, 2011 Share Posted May 24, 2011 it rocks! trancexx it's very convenient, and anybody knows how to call it by php script? thanks Link to comment Share on other sites More sharing options...
Ward Posted May 26, 2011 Share Posted May 26, 2011 Inline ASM in AutoIt x64 is hard before, now _AutoItObject_RegisterObject sovle this problem.AutoItServer + FASMObject = Inline ASM in AutoIt x64I will use this idea and update FASM UDF as soon as possibleThanks, trancexx! 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。 Link to comment Share on other sites More sharing options...
therms Posted January 24, 2012 Share Posted January 24, 2012 This is the best thing I've ever seen on the internet. Thanks for this! mLipok 1 Link to comment Share on other sites More sharing options...
FaridAgl Posted July 11, 2014 Share Posted July 11, 2014 Anyone ever tried this in C++? How to access AutoIt registered objects from C++? http://faridaghili.ir Link to comment Share on other sites More sharing options...
trancexx Posted July 11, 2014 Author Share Posted July 11, 2014 Of course. If you don't mind vanilla flavor: expandcollapse popupMULTI_QI qiResult[1] = { { &IID_IDispatch, nullptr, S_OK } }; OLECHAR* moniker = L"AutoIt.Application"; HRESULT hr = ::CoGetInstanceFromFile(nullptr, nullptr, nullptr, CLSCTX_SERVER, STGM_READWRITE, moniker, 1, qiResult); if (SUCCEEDED(hr)) { IDispatch* pDisp = reinterpret_cast<IDispatch*>(qiResult[0].pItf); OLECHAR* meth = L"Call"; DISPID dispID = 0; hr = pDisp->GetIDsOfNames(IID_NULL, &meth, 1, LOCALE_SYSTEM_DEFAULT, &dispID); if (SUCCEEDED(hr)) { // Invoking function Beep(500, 700) // That means there are three arguments: string "Beep", integer 500 and integer 700 // COM args are backward (first is last and vice versa) VARIANT pArgs[3]; // Last argument is integer 700 ::VariantInit(&pArgs[0]); pArgs[0].vt = VT_INT; pArgs[0].intVal = 700; // Second one is integer 500 ::VariantInit(&pArgs[1]); pArgs[1].vt = VT_INT; pArgs[1].intVal = 500; // And first one is string "Beep" ::VariantInit(&pArgs[2]); pArgs[2].vt = VT_BSTR; pArgs[2].bstrVal = ::SysAllocString(L"Beep"); EXCEPINFO ExcepInfo = {}; // error information if exception occures (initialized) UINT uiArgErr; // index of argument that causes possible error DISPPARAMS dp = {}; // structure required for passing arguments (initialized) // Build DISPPARAMS from the created array of VARIANT-s dp.cArgs = 3; // three arguments dp.rgvarg = pArgs; // array pointer // To collect the result to VARIANT vResult; ::VariantInit(&vResult); hr = pDisp->Invoke(dispID, IID_NULL, LOCALE_SYSTEM_DEFAULT, DISPATCH_METHOD, &dp, &vResult, &ExcepInfo, &uiArgErr); // Clear VARIANTs (this will free strings too) ::VariantClear(&pArgs[0]); ::VariantClear(&pArgs[1]); ::VariantClear(&pArgs[2]); // ALL DONE! } }That's the same as: $oObj = ObjGet("AutoIt.Application") $oObj.Call("Beep", 500, 700); jaberwacky 1 ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
trancexx Posted July 11, 2014 Author Share Posted July 11, 2014 (edited) Don't forget to run server script from the OP first. Edited July 11, 2014 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
FaridAgl Posted July 11, 2014 Share Posted July 11, 2014 Wow, it seems a lot to me. Thanks for the time you put on this, I was in need of something like this (badly). Currently I'm using FileMapping to exchange data between the C++ part and AutoIt part of my app, as I'm developing the whole AutoIt part using AIO, this will make my life much easier (as an IPC method). http://faridaghili.ir Link to comment Share on other sites More sharing options...
13lack13lade Posted July 15, 2014 Share Posted July 15, 2014 I have an assignment which i need to design an application for a business in c# which i currently am unfamiliar with... does this mean that using that, i could potentially write a script in c# which uses autoit functions, includes etc (that i am familiar with) Little confused.. any chance it can be explained in lamens terms? without getting flamed for being a noob lol Link to comment Share on other sites More sharing options...
Andreik Posted December 11, 2015 Share Posted December 11, 2015 Anyone tried this with SQL Server?I tried to run this scriptDECLARE @intResult INT DECLARE @comHandle INT DECLARE @sin float EXEC @intResult = sp_OACreate 'AutoIt.Application', @comHandle OUTPUT, 5 select @intResult, @comHandle EXEC @intResult = sp_OAMethod @comHandle,'Call',@sin OUTPUT,'Sin',254 select @intResult EXEC sp_OADestroy @comHandle select @sinbut sp_OACreate fail to create an instance with error code -2147221005 (invalid object name). I'm not sure if it's the SQL who doesn't have enough privileges to create the instance or if AutoIt server is not visible from SQL Server. Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted December 12, 2015 Share Posted December 12, 2015 I don't know SQL but that has the word "Create" a bunch of times. Are you sure that function corresponds to what in AutoIt would be ObjGet() and not like the more similar sounding ObjCreate()?Also did you have your server script running when you ran that? .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now