Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 03/30/2017 in all areas

  1. I've made this HTTP lib to simplify HTTP requests, mainly when dealing about POST data or file uploads. Three functions are available: string _HTTP_Get ( string $sURL ) string _HTTP_Post ( string $sURL , string $sPostData ) string _HTTP_Upload ( string $sURL , string $sFilePath , string $sFileField , string $sPostData = '' , string $sFilename = Default) Additionaly, two helper functions are also available: URLEncode($sStr) URLDecode($sStr) Full documentation: https://github.com/jesobreira/HTTP.au3/blob/master/README.md Fork me on Github: https://github.com/jesobreira/HTTP.au3 Download lib + docs: https://github.com/jesobreira/HTTP.au3/archive/master.zip
    1 point
  2. martin

    Serial Port /COM Port UDF

    Although serial ports are disappearing, they can still be useful. Here is a COMMs UDF. It provides an easy way to use serial ports without the restrictions and problems some methods have. USB to serial is ok, binary data is ok. This UDF requires my comMG.dll which can be in either the script folder or the Windows folder by default, or in the path specified using the function _CommSetDllPath. Note the following shortcomings: the dll link below is 32 bit so it will not work with a 64 bit apps, but there is a 64 bit version in my post around 25th March 2018 for people to try. The strings and character functions are all AnsiChar. Functions in the UDF are _CommVersion _CommListPorts _CommSetPort _CommPortConnection _CommClearOutputBuffer _CommClearInputBuffer _CommGetInputcount _CommGetOutputcount _CommSendString _CommGetString _CommGetLine _CommReadByte _CommReadChar _CommSendByte _CommSendBreak; not tested!!!!!!!!!! _CommCloseport _CommSwitch _CommReadByteArray _CommSendByteArray _CommsetTimeouts _CommSetXonXoffProperties _CommSetRTS (NB these will not work if Hardware handshaking is selected because _CommSetDTR then these lines are controlled by the data being sent.) _CommSetDllPath _CommGetLineStates -------------------------------------------------------------------------------------------------------------------------------- Go to Download Page For Commgv2 Download includes the dll and udf. Most recent changes 28th March 2014 - dll V2.83 Correct error setting 6 data bits as 7. 11th March 2014 dll V2.82 Allow data bits of 4 to 8 instead of only 7 and 8. 19th August 2013 dll v2.81 removes some unwanted eroor message popups. Might not remove popups for some Windows versions. 27th September 2012 Correct error closing port. New version of UDF if V2.90, new dll is commg.dll V2.79. Thanks to tfabris. 18th January 2012 Corrected typo in UDF V 2.87, and uploaded as V2.88 Increased max baud allowed by the dll from 200000 to 256000. New version now V2.78 17th January 2012 Modified thesleep addition to _CommGetLine so that reading data is not slowed down. 14th January 2012 Corrected _CommReadByte in UDF. Added sleep(20) to while loop in _CommGetLine to reduce CPU usage 20th December 2011 UDF version 2.86. - Changed function GetByte so it returned the error string given by the dll. Dll version 2.77 - removed an unwanted erro message dialogue from GetByte function. (Thanks funkey) 4th December 2011 New dll and example versions. Dll function SetPort corrected because it was not using the parameters passed for DTR and RTS. The example was setting flow control incorrectly: the settings for hardware handshaking and XON./XOFF were reversed. 25th August 2011 corrected function _CommClosePort. Example corrected for setting parity and flow 22nd December 2013 (thanks to MichaelXMike) mgrefcommg CommgExample.au3
    1 point
  3. Which is strange because using your .htm file it fills out fine for me, using any of the code I posted above.
    1 point
  4. Here is the .bat File I use. I love Autoit but when I can do it with native .BAT files I usually go that route. @ECHO OFF TITLE Adding Fonts.. REM Filename: ADD_Fonts.cmd REM Script to ADD TrueType and OpenType Fonts for Windows REM How to use: REM Place the batch file inside the folder of the font files OR: REM Optional Add source folder as parameter with ending backslash and dont use quotes, spaces are allowed REM example "ADD_fonts.cmd" C:\Folder 1\Folder 2\ IF NOT "%*"=="" SET SRC=%* ECHO. ECHO Adding Fonts.. ECHO. FOR /F %%i in ('dir /b "%SRC%*.*tf"') DO CALL :FONT %%i REM OPTIONAL REBOOT REM shutdown -r -f -t 10 -c "Reboot required for Fonts installation" ECHO. ECHO Done! PAUSE EXIT :FONT ECHO. REM ECHO FILE=%~f1 SET FFILE=%~n1%~x1 SET FNAME=%~n1 SET FNAME=%FNAME:-= % IF "%~x1"==".otf" SET FTYPE=(OpenType) IF "%~x1"==".ttf" SET FTYPE=(TrueType) ECHO FILE=%FFILE% ECHO NAME=%FNAME% ECHO TYPE=%FTYPE% COPY /Y "%SRC%%~n1%~x1" "%SystemRoot%\Fonts\" reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%FNAME% %FTYPE%" /t REG_SZ /d "%FFILE%" /f GOTO :EOF
    1 point
  5. Sooo...after long waiting the ISN AutoIt Studio Version 1.04 is finally out! Happy testing! Changelog: (translated by google) -> ISN AutoIt Studio: <- ----------------------------------- - Bugfix: Various bug fixes - Bugfix: The navigation menu in the program settings now has a scroll bar (if too many elements are open) - Bugfix: CPU utilization of the ISN optimized at idle - Bugfix: MDI windows of the ISN AutoIt Studios can no longer be moved out of the desktop by accident - Bugfix: If the ISN Form Studio was active, the ISN could not be restored from the taskliste. This is now fixed! (FINALLY!) - Bugfix: Chinese Encoding improved - NEW: Italian language update (thx to Stefano cerbioni) - NEW: Chiesian language update (thx to bfgxp) - NEW: The position and size of the main window can now be saved when the ISN AutoIt Studio is terminated and restored the next time you start it. This option can be activated in the program settings under "Display". - NEW: Under "Edit" you will find a new entry: Select line (s) / Remove marking (Hotkey: CTRL + F2) - NEW: The area in which are now only the program log was displayed, is now marked as "QuickView" area. This window area can now have several functions. (The contents can be changed via Tabs) - NEW: In the new QuickView window of the ISN there is now a small code storage. In the end, only a small text field in case something is fast Down, or copy. The code store will not be saved and will automatically empty as soon as the project is closed. - NEW: The ISN AutoIt Studio now has its own ToDo list for your projects! You can assign your own categories here and enter tasks. The ToDo list is also displayed in the new "QuickView" window area. Info: The ToDo list requires Windows Vista or higher for correct display! - NEW: The full screen mode is now activated on the monitor on which the ISN window is currently located. - NEW: In the program settings there is now a new entry named "Tools". Here you can deactivate various integrated tools of the ISN AutoIt Studio. (Eg the bit-operation tester or the new PELock AutoIt Obfuscator) - NEW: The PELock AutoIt Obfuscator is now integrated in the ISN AutoIt Studio! (To be found under Tools or in the context menu of the project tree) The whole can be deactivated, of course, on request. (Program Settings -> Tools) In order to use the Obfuscator in full, a license is required! Find out more about the PELock AutoIt Obfuscator at https://www.pelock.com/products/autoit-obfuscator - NEW: The ISN AutoIt Studio can now also use language files (* .lng) in UTF-8 format. - NEW: The config.ini is now created as standard UTF-16 (LE) file. The file is automatically converted to the new format when the ISN is started. - NEW: The project files (* .isn) are now saved as standard with UTF-16 (LE) coding. This should solve problems with other languages (eg Chinese) or umlauts. The conversion is started as soon as a project is opened. (Infomission is displayed) The current project file (* .isn) is renamed to * .bak and can be deleted, if no problems occur. The whole also applies to templates! (The "Default" template is automatically converted when the ISN is started!) -> ISN Form Studio 2: <- ----------------------------------- - Bugfix: Various bug fixes - Bugfix: Chinese Encoding improved - NEW: Chiesian language update (thx to bfgxp) -> Homepage (http://www.isnetwork.at): <- ----------------------------------- - NEW: The homepage, the forum and the bugtracker are now all accessible via HTTPS! -> Plugin SDK: <- ----------------------------------- - NEW: Function _ISNPlugin_Get_langstring extended by the new UTF8 encoding.
    1 point
  6. Chimp, This was a good laugh. ptrex, Add some Switch statements to the bottom of the event handler. Here demonstrated with MsgBoxes. Note that the MsgBoxes are not blocking. You can use Tab to navigate between buttons and Enter/Space to click. tst01.au3 ;#AutoIt3Wrapper_UseX64=y #include "CLR.au3" Example() ; Form Using System.Windows.Forms.Form Func Example() ; Compile the helper class. This could be pre-compiled. Local $oHelper, $oHelperAsm = _CLR_CompileCSharp( FileRead( "EventHelper.cs" ) ) $oHelperAsm.CreateInstance( "EventHelper", $oHelper ) ConsoleWrite( "IsObj( $oHelper ) = " & IsObj( $oHelper ) & @CRLF ) ConsoleWrite( "_CLR_LoadLibrary System.Windows.Forms" & @CRLF ) Local $oAssembly = _CLR_LoadLibrary( "System.Windows.Forms" ) ConsoleWrite( "IsObj( $oAssembly ) = " & IsObj( $oAssembly ) & @CRLF ) ConsoleWrite( @CRLF & "_CRL_CreateObject: System.Windows.Forms.Form" & @CRLF ) Local $oForm = _CRL_CreateObject( $oAssembly, "System.Windows.Forms.Form" ) ConsoleWrite( "IsObj( $oForm ) = " & IsObj( $oForm ) & @CRLF ) $oForm.Text = "Form From Net - AutoIt Rocks" $oForm.Width = 800 $oForm.Height = 400 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.Button" & @CRLF ) Local $oButton1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button") $oButton1.Text = "button1" $oButton1.Width = 60 $oButton1.Height = 30 $oButton1.Left = 100 $oButton1.Top = 100 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.Button" & @CRLF ) Local $oButton2 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button") $oButton2.Text = "button2" $oButton2.Width = 60 $oButton2.Height = 30 $oButton2.Left = $oButton1.Right + 50 $oButton2.Top = $oButton1.Top Local $hEventHandler = DllCallbackRegister( "EventHandler", "int", "ptr" ) Local $pEventHandler = DllCallbackGetPtr( $hEventHandler ) ; Add an event handler for the "OnEvent" event. Use "" to pass the ; address as a string, since IDispatch doesn't support 64-bit integers. $oHelper.AddHandler( $oButton1, "Click", $pEventHandler ) $oHelper.AddHandler( $oButton2, "Click", $pEventHandler ) ;$oForm.Controls.Add( $oButton1 ) ; ERR $oButton1.Parent = $oForm ; OK $oButton2.Parent = $oForm ; OK $oForm.ShowDialog() $oForm.Dispose() EndFunc ; Our event handler is called with a SAFEARRAY of parameters. This ; makes it much easier to get the type and value of each parameter. Func EventHandler( $pprm ) ConsoleWrite( "$pprm = " & $pprm & @CRLF ) Local $iDim = SafeArrayGetDim( $pprm ) ConsoleWrite( "$iDim = " & $iDim & @CRLF ) Local $iLBound, $iUBound SafeArrayGetLBound( $pprm, 1, $iLBound ) SafeArrayGetUBound( $pprm, 1, $iUBound ) ConsoleWrite( "$iLBound = " & $iLBound & @CRLF ) ConsoleWrite( "$iUBound = " & $iUBound & @CRLF ) Local $tprm = DllStructCreate( $tagSAFEARRAY, $pprm ) Local $fFeatures = DllStructGetData( $tprm, "fFeatures" ) ConsoleWrite( "$fFeatures = 0x" & Hex( $fFeatures ) & @CRLF ) Local $cbElements = DllStructGetData( $tprm, "cbElements" ) ConsoleWrite( "$cbElements = " & $cbElements & @CRLF ) Local $vt SafeArrayGetVartype( $pprm, $vt ) ConsoleWrite( "$vt = " & $vt & @CRLF ) Local $prmData, $tvt, $data, $obj SafeArrayAccessData( $pprm, $prmData ) $tvt = DllStructCreate( "word", $prmData ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) Local $sCtrlInfo = $obj.ToString() ConsoleWrite( $sCtrlInfo & @CRLF ) $tvt = DllStructCreate( "word", $prmData + ( @AutoItX64 ? 24 : 16 ) ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + ( @AutoItX64 ? 24 : 16 ) + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) ConsoleWrite( $obj.ToString() & @CRLF ) SafeArrayUnaccessData( $pprm ) Local $aCtrlInfo = StringSplit( $sCtrlInfo, ", ", 2 ) ; 2 = $STR_NOCOUNT For $i = 0 To UBound( $aCtrlInfo ) - 1 ConsoleWrite( "$i = " & $i & ", $aCtrlInfo[$i] = " & $aCtrlInfo[$i] & @CRLF ) Next Switch $aCtrlInfo[0] Case "System.Windows.Forms.Button" Switch $aCtrlInfo[3] Case "button1" MsgBox( 0, "", "button1" ) Case "button2" MsgBox( 0, "", "button2" ) EndSwitch EndSwitch EndFunc ; In the end we still want the autoit object. This function converts a raw pointer to an autoit object Func ConvertPtrToIDispatch($IDispatch_Ptr) ; This would have been 10000x easier if autoit had supported the idispatch* type in dllstructs... ; Fortunetely memcpy can copy the pointer into a idispatch*, lucky us. $ptr_struct=DllStructCreate("ptr") DllStructSetData($ptr_struct,1,$IDispatch_Ptr) $aCall = DllCall("ntdll.dll","ptr:cdecl","memcpy","idispatch*","","ptr",DllStructGetPtr($ptr_struct),"long",4) return $aCall[1] EndFunc
    1 point
  7. rootx, You will need to read the ini file into an array, preprocess the [ & ] characters which are not bounding the section and then rewrite it - something like this: #include <Array.au3> #include <File.au3> $sPath = "C: \ name [IBIS 001] 2017\file.txt" $sIniFile = "Test.ini" $hFile = FileOpen($sIniFile, $FO_OVERWRITE) FileWrite($hFile, "[" & $sPath & "]" & @CRLF & "Key=Value") FileClose($hFile) Global $aLines _FileReadToArray($sIniFile, $aLines) _ArrayDisplay($aLines, "Original ini content", Default, 8) For $i = 1 To $aLines[0] ; Look for the section names If StringLeft($aLines[$i], 1) = "[" Then ; Extract the sectionname from within the [ & ] $sSectionName = StringTrimLeft(StringtrimRight($aLines[$i], 1), 1) ; Escape any [ & ] and rewrit ewith the external [ & ] $aLines[$i] = "[" & StringReplace(StringReplace($sSectionName, "[", "\5B"), "]", "\5D") & "]" EndIf Next ; Now rewrite the escaped ini file _FileWriteFromArray($sIniFile, $aLines, 1) ; Now read it $aSections = IniReadSectionNames($sIniFile) For $i = 1 To $aSections[0] $aSections[$i] = StringReplace(StringReplace($aSections[$i], "\5B", "["), "\5D", "]") Next _ArrayDisplay($aSections, "Section names from ini", Default, 8) M23
    1 point
  8. Just over a month ago, I created a viewer (ASCII Checker) to help with determining INI entry issues. It might be of some help to you, and can be found here. There is also a link in the quoted section, to a Wikipedia article about INI files and escape characters.
    1 point
  9. Do you think about this ? http://docs.attachmate.com/extra/x-treme/apis/com/
    1 point
  10. Hello Yes you can. #RequireAdmin ; for this example to have sense #include <MsgBoxConstants.au3> #include <ProcessConstants.au3> #include <Security.au3> #include <SecurityConstants.au3> #include <StructureConstants.au3> #include <WinAPI.au3> Local $sCommand = _ 'Local ' & _ '$Dummy1 = MsgBox(0,"Am I Admin?", "IsAdmin: " & IsAdmin())' $sCommand = '"' & StringReplace($sCommand, '"', '""') & '"' ConsoleWrite($sCommand & @CRLF) ;~ Run(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand) _RunNonElevatedAndWait(@AutoItExe & ' /AutoIt3ExecuteLine ' & $sCommand) Func _RunNonElevatedAndWait($sCommandLine = "") If Not IsAdmin() Then Return Run($sCommandLine) ; if current process is run non-elevated then just Run new one. ; Structures needed for creating process Local $tSTARTUPINFO = DllStructCreate($tagSTARTUPINFO) Local $tPROCESS_INFORMATION = DllStructCreate($tagPROCESS_INFORMATION) ; Process handle of some process that's run non-elevated. For example "Explorer" Local $hProcess = _WinAPI_OpenProcess($PROCESS_ALL_ACCESS, 0, ProcessExists("explorer.exe")) ; If successful If $hProcess Then ; Token... Local $hTokOriginal = _Security__OpenProcessToken($hProcess, $TOKEN_ALL_ACCESS) ; Process handle is no longer needed. Close it _WinAPI_CloseHandle($hProcess) ; If successful If $hTokOriginal Then ; Duplicate the original token Local $hTokDuplicate = _Security__DuplicateTokenEx($hTokOriginal, $TOKEN_ALL_ACCESS, $SECURITYIMPERSONATION, $TOKENPRIMARY) ; Close the original token _WinAPI_CloseHandle($hTokOriginal) ; If successful If $hTokDuplicate Then ; Create process with this new token _Security__CreateProcessWithToken($hTokDuplicate, 0, $sCommandLine, 0, @ScriptDir, $tSTARTUPINFO, $tPROCESS_INFORMATION) ; Close that token _WinAPI_CloseHandle($hTokDuplicate) ; Close get handles _WinAPI_CloseHandle(DllStructGetData($tPROCESS_INFORMATION, "hProcess")) _WinAPI_CloseHandle(DllStructGetData($tPROCESS_INFORMATION, "hThread")) ; Return PID of newly created process Return ProcessWaitClose(DllStructGetData($tPROCESS_INFORMATION, "ProcessID")) EndIf EndIf EndIf EndFunc ;==>_RunNonElevated Saludos
    1 point
  11. Event_handling.au3: ;#AutoIt3Wrapper_UseX64=y #include "CLR.au3" Example() Func Example() ; Compile the helper class. This could be pre-compiled. Local $oHelper, $oHelperAsm = _CLR_CompileCSharp( FileRead( "EventHelper.cs" ) ) $oHelperAsm.CreateInstance( "EventHelper", $oHelper ) ConsoleWrite( "IsObj( $oHelper ) = " & IsObj( $oHelper ) & @CRLF ) ; Create our test object, which simply exposes a single event. Local $oTest, $oTestAsm = _CLR_CompileCSharp( FileRead( "TestObject.cs" ) ) $oTestAsm.CreateInstance( "ObjectWithEvent", $oTest ) ConsoleWrite( "IsObj( $oTest ) = " & IsObj( $oTest ) & @CRLF ) Local $hEventHandler = DllCallbackRegister( "EventHandler", "int", "ptr" ) Local $pEventHandler = DllCallbackGetPtr( $hEventHandler ) ; Add an event handler for the "OnEvent" event. Use "" to pass the ; address as a string, since IDispatch doesn't support 64-bit integers. $oHelper.AddHandler( $oTest, "OnEvent", $pEventHandler ) ; Make an event handler (event must be of the EventHandler type). Local $oHandler = $oHelper.MakeHandler( $pEventHandler ) $oTest.add_OnEvent( $oHandler ) ; Test the event handlers. $oTest.RaiseEvent() EndFunc ; Our event handler is called with a SAFEARRAY of parameters. This ; makes it much easier to get the type and value of each parameter. Func EventHandler( $pprm ) ConsoleWrite( "$pprm = " & $pprm & @CRLF ) Local $iDim = SafeArrayGetDim( $pprm ) ConsoleWrite( "$iDim = " & $iDim & @CRLF ) Local $iLBound, $iUBound SafeArrayGetLBound( $pprm, 1, $iLBound ) SafeArrayGetUBound( $pprm, 1, $iUBound ) ConsoleWrite( "$iLBound = " & $iLBound & @CRLF ) ConsoleWrite( "$iUBound = " & $iUBound & @CRLF ) Local $tprm = DllStructCreate( $tagSAFEARRAY, $pprm ) Local $fFeatures = DllStructGetData( $tprm, "fFeatures" ) ConsoleWrite( "$fFeatures = 0x" & Hex( $fFeatures ) & @CRLF ) Local $cbElements = DllStructGetData( $tprm, "cbElements" ) ConsoleWrite( "$cbElements = " & $cbElements & @CRLF ) Local $vt SafeArrayGetVartype( $pprm, $vt ) ConsoleWrite( "$vt = " & $vt & @CRLF ) Local $prmData, $tvt, $data, $obj SafeArrayAccessData( $pprm, $prmData ) $tvt = DllStructCreate( "word", $prmData ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) ConsoleWrite( $obj.ToString() & @CRLF ) $tvt = DllStructCreate( "word", $prmData + ( @AutoItX64 ? 24 : 16 ) ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + ( @AutoItX64 ? 24 : 16 ) + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) ConsoleWrite( $obj.ToString() & @CRLF ) SafeArrayUnaccessData( $pprm ) EndFunc ; In the end we still want the autoit object. This function converts a raw pointer to an autoit object Func ConvertPtrToIDispatch($IDispatch_Ptr) ; This would have been 10000x easier if autoit had supported the idispatch* type in dllstructs... ; Fortunetely memcpy can copy the pointer into a idispatch*, lucky us. $ptr_struct=DllStructCreate("ptr") DllStructSetData($ptr_struct,1,$IDispatch_Ptr) $aCall = DllCall("ntdll.dll","ptr:cdecl","memcpy","idispatch*","","ptr",DllStructGetPtr($ptr_struct),"long",4) return $aCall[1] EndFunc EventHelper.cs using System; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; public class EventHelper { // Delegate type for the AutoHotkey callback. public delegate void CallbackType([MarshalAs(UnmanagedType.SafeArray)] object[] argv); // AddHandler: Adds a callback as a handler for the given event of the given object. public void AddHandler(object target, string eventName, string pcb) { var cb = ParseCB(pcb); // Reference: http://msdn.microsoft.com/en-us/library/ms228976 EventInfo evt = target.GetType().GetEvent(eventName); Type handlerType = evt.EventHandlerType; MethodInfo handlerSig = handlerType.GetMethod("Invoke"); ParameterInfo[] parameters = handlerSig.GetParameters(); Type[] parameterTypes = new Type[parameters.Length+1]; parameterTypes[0] = typeof(CallbackType); for (int i = 0; i < parameters.Length; i++) parameterTypes[i+1] = parameters[i].ParameterType; var handler = new DynamicMethod("", handlerSig.ReturnType, parameterTypes, true); var il = handler.GetILGenerator(); var loc = il.DeclareLocal(typeof(object[])); il.Emit(OpCodes.Ldc_I4_2); il.Emit(OpCodes.Newarr, typeof(object)); il.Emit(OpCodes.Stloc_0); il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4_0); il.Emit(OpCodes.Ldarg_1); il.Emit(OpCodes.Stelem_Ref); il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Ldc_I4_1); il.Emit(OpCodes.Ldarg_2); il.Emit(OpCodes.Stelem_Ref); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldloc_0); il.Emit(OpCodes.Call, typeof(CallbackType).GetMethod("Invoke")); il.Emit(OpCodes.Ret); var delg = handler.CreateDelegate(handlerType, cb); var adder = evt.GetAddMethod(); adder.Invoke(target, new object[] { delg }); } // Much simpler method, restricted to a specific delegate type. public EventHandler MakeHandler(string pcb) { var cb = ParseCB(pcb); return (sender, e) => cb(new object[]{ sender, e }); } public CallbackType ParseCB(string cb) { // For 32-bit, simply marking the parameter of AddHandler/MakeHandler with: // [MarshalAs(UnmanagedType.FunctionPtr)] CallbackType cb // is adequate, but since IDispatch doesn't support 64-bit integers, // we have to pass the callback address as a string for x64 builds. return (CallbackType) Marshal.GetDelegateForFunctionPointer( (IntPtr)Int64.Parse(cb), typeof(CallbackType)); } } TestObject.cs public class ObjectWithEvent { public void RaiseEvent() { if (OnEvent != null) OnEvent(this, System.EventArgs.Empty); } public event System.EventHandler OnEvent; } tst00.au3 ;#AutoIt3Wrapper_UseX64=y #include "CLR.au3" Example() ; Form Using System.Windows.Forms.Form Func Example() ; Compile the helper class. This could be pre-compiled. Local $oHelper, $oHelperAsm = _CLR_CompileCSharp( FileRead( "EventHelper.cs" ) ) $oHelperAsm.CreateInstance( "EventHelper", $oHelper ) ConsoleWrite( "IsObj( $oHelper ) = " & IsObj( $oHelper ) & @CRLF ) ConsoleWrite( "_CLR_LoadLibrary System.Windows.Forms" & @CRLF ) Local $oAssembly = _CLR_LoadLibrary( "System.Windows.Forms" ) ConsoleWrite( "IsObj( $oAssembly ) = " & IsObj( $oAssembly ) & @CRLF ) ConsoleWrite( @CRLF & "_CRL_CreateObject: System.Windows.Forms.Form" & @CRLF ) Local $oForm = _CRL_CreateObject( $oAssembly, "System.Windows.Forms.Form" ) ConsoleWrite( "IsObj( $oForm ) = " & IsObj( $oForm ) & @CRLF ) $oForm.Text = "Form From Net - AutoIt Rocks" $oForm.Width = 800 $oForm.Height = 400 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.Button" & @CRLF ) Local $oButton1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button") $oButton1.Text = "button" $oButton1.Width = 60 $oButton1.Height = 30 Local $hEventHandler = DllCallbackRegister( "EventHandler", "int", "ptr" ) Local $pEventHandler = DllCallbackGetPtr( $hEventHandler ) ; Add an event handler for the "OnEvent" event. Use "" to pass the ; address as a string, since IDispatch doesn't support 64-bit integers. $oHelper.AddHandler( $oButton1, "Click", $pEventHandler ) ;$oForm.Controls.Add( $oButton1 ) ; ERR $oButton1.Parent = $oForm ; OK $oForm.ShowDialog() $oForm.Dispose() EndFunc ; Our event handler is called with a SAFEARRAY of parameters. This ; makes it much easier to get the type and value of each parameter. Func EventHandler( $pprm ) ConsoleWrite( "$pprm = " & $pprm & @CRLF ) Local $iDim = SafeArrayGetDim( $pprm ) ConsoleWrite( "$iDim = " & $iDim & @CRLF ) Local $iLBound, $iUBound SafeArrayGetLBound( $pprm, 1, $iLBound ) SafeArrayGetUBound( $pprm, 1, $iUBound ) ConsoleWrite( "$iLBound = " & $iLBound & @CRLF ) ConsoleWrite( "$iUBound = " & $iUBound & @CRLF ) Local $tprm = DllStructCreate( $tagSAFEARRAY, $pprm ) Local $fFeatures = DllStructGetData( $tprm, "fFeatures" ) ConsoleWrite( "$fFeatures = 0x" & Hex( $fFeatures ) & @CRLF ) Local $cbElements = DllStructGetData( $tprm, "cbElements" ) ConsoleWrite( "$cbElements = " & $cbElements & @CRLF ) Local $vt SafeArrayGetVartype( $pprm, $vt ) ConsoleWrite( "$vt = " & $vt & @CRLF ) Local $prmData, $tvt, $data, $obj SafeArrayAccessData( $pprm, $prmData ) $tvt = DllStructCreate( "word", $prmData ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) ConsoleWrite( $obj.ToString() & @CRLF ) $tvt = DllStructCreate( "word", $prmData + ( @AutoItX64 ? 24 : 16 ) ) $vt = DllStructGetData( $tvt, 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF ) ; EventArgs Class $data = DllStructGetData( DllStructCreate( "ptr", $prmData + ( @AutoItX64 ? 24 : 16 ) + 8 ), 1 ) $obj = ConvertPtrToIDispatch($data) ConsoleWrite( $obj.ToString() & @CRLF ) SafeArrayUnaccessData( $pprm ) EndFunc ; In the end we still want the autoit object. This function converts a raw pointer to an autoit object Func ConvertPtrToIDispatch($IDispatch_Ptr) ; This would have been 10000x easier if autoit had supported the idispatch* type in dllstructs... ; Fortunetely memcpy can copy the pointer into a idispatch*, lucky us. $ptr_struct=DllStructCreate("ptr") DllStructSetData($ptr_struct,1,$IDispatch_Ptr) $aCall = DllCall("ntdll.dll","ptr:cdecl","memcpy","idispatch*","","ptr",DllStructGetPtr($ptr_struct),"long",4) return $aCall[1] EndFunc
    1 point
  12. @Malkey I think AnonymousX was just pointing out that the $oneDarray is still a 2D array but with one column and so can't be referenced as a 1D array. Hope that made sense.
    1 point
  13. I think InunoTaishou meant: Run("C:\soft\7z x C:\_soft\tst.7z -oC:\_Soft")
    1 point
  14. I think -o* is the argument you want "C:\soft\7z x -oC:\_soft\tst.7z"
    1 point
  15. I guess what you will find is: to manage code snippets in AutoIt freeware portable for use on a USB stick password protected so nobody can read the code snippets
    1 point
  16. That's because you pass the Subject as parameter to _OL_ItemPrint. Use the EntryID instead: Global $aItems = _OL_ItemFind($oOutlook, "*\Posteingang", $olMail, "", "Subject", "Menorca", "EntryID,Subject", "", 1)
    1 point
×
×
  • Create New...