Leaderboard
Popular Content
Showing content with the highest reputation on 04/01/2017 in all areas
-
I very long time was using In the end, I found that at present my needs I need to modify it. And here it is: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N #Region INCLUDE ;################################## ; Include ;################################## #include <file.au3> #EndRegion INCLUDE #Region Variables ;################################## ; Variables ;################################## Global Enum _ $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _ $g__INetSmtpMailCom_ERROR_Send, _ $g__INetSmtpMailCom_ERROR_ObjectCreation, _ $g__INetSmtpMailCom_ERROR_COUNTER Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory. Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification Global Const $g__cdoAnonymous = 0 ; Do not authenticate Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication Global Const $g__cdoNTLM = 2 ; NTLM ; Delivery Status Notifications Global Const $g__cdoDSNDefault = 0 ; None Global Const $g__cdoDSNNever = 1 ; None Global Const $g__cdoDSNFailure = 2 ; Failure Global Const $g__cdoDSNSuccess = 4 ; Success Global Const $g__cdoDSNDelay = 8 ; Delay Global Const $g__cdoDSNSuccessFailOrDelay = 14 ; Success, failure or delay #EndRegion Variables #Region Example Script ;################################## ; Example Script ;################################## ;~ _Example() Func _Example() Local $sSmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED Local $sFromName = "Name" ; name from who the email was sent Local $sFromAddress = "your@Email.Address.com" ; address from where the mail should come Local $sToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED Local $sSubject = "Userinfo" ; subject from the email - can be anything you want it to be Local $sBody = "" ; the messagebody from the mail - can be left blank but then you get a blank mail Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Local $sCcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed Local $sBccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low" Local $sUsername = "******" ; username for the account used from where the mail gets sent - REQUIRED Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED Local $iIPPort = 25 ; port used for sending the mail Local $bSSL = False ; enables/disables secure socket layer sending - set to True if using httpS ; Local $iIPPort = 465 ; GMAIL port used for sending the mail ; Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS Local $bIsHTMLBody = False Local $iDSNOptions = $g__cdoDSNDefault Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions) If @error Then MsgBox(0, "_INetSmtpMailCom(): Error sending message", _ "Error code: " & @error & @CRLF & @CRLF & _ "Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _ "Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _ "Description (rc): " & $rc & @CRLF & @CRLF & _ "ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _ ) ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF) EndIf EndFunc ;==>_Example #EndRegion Example Script #Region UDF Functions ; The UDF ; #FUNCTION# ==================================================================================================================== ; Name ..........: _INetSmtpMailCom ; Description ...: ; Syntax ........: _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress[, $s_Subject = ""[, $as_Body = ""[, ; $s_AttachFiles = ""[, $s_CcAddress = ""[, $s_BccAddress = ""[, $s_Importance = "Normal"[, $s_Username = ""[, ; $s_Password = ""[, $IPPort = 25[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]]) ; Parameters ....: $s_SmtpServer - A string value. ; $s_FromName - A string value. ; $s_FromAddress - A string value. ; $s_ToAddress - A string value. ; $s_Subject - [optional] A string value. Default is "". ; $s_Body - [optional] A string value. Default is "". ; $s_AttachFiles - [optional] A string value. Default is "". ; $s_CcAddress - [optional] A string value. Default is "". ; $s_BccAddress - [optional] A string value. Default is "". ; $s_Importance - [optional] A string value. Default is "Normal". ; $s_Username - [optional] A string value. Default is "". ; $s_Password - [optional] A string value. Default is "". ; $IPPort - [optional] An integer value. Default is 25. ; $bSSL - [optional] A binary value. Default is False. ; $bIsHTMLBody - [optional] A binary value. Default is False. ; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault. ; Return values .: None ; Author ........: Jos ; Modified ......: mLipok ; Remarks .......: ; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/ ; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/ ; Example .......: Yes ; =============================================================================================================================== Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault) ; init Error Handler _INetSmtpMailCom_ErrObjInit() Local $objEmail = ObjCreate("CDO.Message") If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) ; Clear previous Err information _INetSmtpMailCom_ErrHexNumber(0) _INetSmtpMailCom_ErrDescription('') _INetSmtpMailCom_ErrScriptLine('') $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject ; Select whether or not the content is sent as plain text or HTM If $bIsHTMLBody Then $objEmail.Textbody = $s_Body & @CRLF Else $objEmail.HTMLBody = $s_Body EndIf ; Add Attachments If $s_AttachFiles <> "" Then Local $S_Files2Attach = StringSplit($s_AttachFiles, ";") For $x = 1 To $S_Files2Attach[0] $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x]) If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0) EndIf Next EndIf ; Set Email Configuration $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = $g__cdoBasic $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL ;Update Configuration Settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch ; Set DSN options If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then $objEmail.DSNOptions = $iDSNOptions $objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress ;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress EndIf ; Update Importance and Options fields $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then _INetSmtpMailCom_ErrObjCleanUp() Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription()) EndIf ; CleanUp $objEmail = "" _INetSmtpMailCom_ErrObjCleanUp() EndFunc ;==>_INetSmtpMailCom ; ; Com Error Handler Func _INetSmtpMailCom_ErrObjInit($bParam = Default) Local Static $oINetSmtpMailCom_Error = Default If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then $oINetSmtpMailCom_Error = '' Return $oINetSmtpMailCom_Error EndIf If $oINetSmtpMailCom_Error = Default Then $oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc") EndIf Return $oINetSmtpMailCom_Error EndFunc ;==>_INetSmtpMailCom_ErrObjInit Func _INetSmtpMailCom_ErrObjCleanUp() _INetSmtpMailCom_ErrObjInit('CleanUp') EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp Func _INetSmtpMailCom_ErrHexNumber($vData = Default) Local Static $vReturn = 0 If $vData <> Default Then $vReturn = $vData Return $vReturn EndFunc ;==>_INetSmtpMailCom_ErrHexNumber Func _INetSmtpMailCom_ErrDescription($sData = Default) Local Static $sReturn = '' If $sData <> Default Then $sReturn = $sData Return $sReturn EndFunc ;==>_INetSmtpMailCom_ErrDescription Func _INetSmtpMailCom_ErrScriptLine($iData = Default) Local Static $iReturn = '' If $iData <> Default Then $iReturn = $iData Return $iReturn EndFunc ;==>_INetSmtpMailCom_ErrScriptLine Func _INetSmtpMailCom_ErrFunc() _INetSmtpMailCom_ErrObjInit() _INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8)) _INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3)) _INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine) SetError(1); something to check for when this function returns Return EndFunc ;==>_INetSmtpMailCom_ErrFunc #EndRegion UDF Functions Creating this modification, I had to: 1. Object Error Handler used only for the duration of the function of Use, 2. Automatic ErrorHandler CleanUp so that previous ErrorHandler took the job. 3. Ability to get ErrorNumber and ErrorDescription ErrorScriptLine information even after the end of the function 4. Elimination of most global variables mLipok EDIT: attached SmtpMailer_UDF.au3 file EDIT 2: Any comments are welcome. EDIT 3: Script CleanUp EDIT 4: Download moved to "Download Section" (previously downloaded 379 times) EDIT 5: at 2016/01/31 there was many script breaking changes1 point
-
You don't need to use .Equals to compare objects. AutoIt can do that by itself. Besides this all can be reduced on both sides, maybe like this: EventHelper.cs using System; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; public class EventHelper { // Delegate type for the AutoIt callback. public delegate void CallbackType([MarshalAs(UnmanagedType.LPArray)] object[] argv); public EventHandler MakeHandler([MarshalAs(UnmanagedType.FunctionPtr)] CallbackType cb) { return (sender, e) => cb( new[] {sender} ); } } And then the last example LarsJ posted #include "CLR.au3" Global $aObjects[2] 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 $aObjects[0] = $oButton1 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 $aObjects[1] = $oButton2 Local $hEventHandler = DllCallbackRegister("EventHandler", "int", "ptr") Local $pEventHandler = DllCallbackGetPtr($hEventHandler) ; Make an event handler (event must be of the EventHandler type). Local $oHandler = $oHelper.MakeHandler($pEventHandler) $oButton1.add_Click($oHandler) $oButton2.add_Click($oHandler) $oButton1.Parent = $oForm ; OK $oButton2.Parent = $oForm ; OK $oForm.ShowDialog() $oForm.Dispose() EndFunc ; Event handler is called with a LPArray of 1 parameter (variant pointer). Func EventHandler($pprm) ConsoleWrite("$pprm = " & $pprm & @CRLF) Local $vVar = DllStructCreate($tagVARIANT, $pprm) $obj = ObjCreateInterface(DllStructGetData($vVar, "data"), $sIID_IDispatch) For $i = 0 To UBound($aObjects) - 1 If $obj = $aObjects[$i] Then MsgBox(0, "", $obj.ToString(), 0, $obj.Handle) ; give it parent handle not to have ten boxes one over other ExitLoop EndIf Next EndFunc1 point
-
Hi Larsj, Nice you reworked the EventHandler in clean code ... ! I added some more controls to the Example : Label CheckBox TextBox ComboBox Listview : issues here adding columns ?! ;#AutoIt3Wrapper_UseX64=y #include "CLR.au3" Global $aObjects[2] Example() ; Form Using System.Windows.Forms.Form Func Example() #Region Register EventHelper ; 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 ) #EndRegion #Region Add Controls 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 1" & @CRLF ) Local $oButton1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Button") $oButton1.Text = "button1" $oButton1.Width = 60 $oButton1.Height = 30 $oButton1.Left = 40 $oButton1.Top = 10 $aObjects[0] = $oButton1 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.Button 2" & @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 $aObjects[1] = $oButton2 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.checkbox" & @CRLF ) Local $checkbox1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.checkbox") $checkbox1.Top = 55 $checkbox1.Left = 155 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.ComboBox" & @CRLF ) Local $Combo = _CRL_CreateObject($oAssembly, "System.Windows.Forms.ComboBox") $Combo.Width = 50 $Combo.Top = 15 $Combo.Left = 290 For $i = 1 to 4 $Combo.Items.Add("test" & $i) Next ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.Label" & @CRLF ) Local $Label = _CRL_CreateObject($oAssembly, "System.Windows.Forms.Label") $Label.Width = 140 $Label.Top = 55 $Label.Left = 15 ;~ $Label.Font = "Microsoft Sans Serif, 18pt, style=Bold, Italic" ; Does not Work $Label.Text = "Press The Buttons ..." ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.TextBox" & @CRLF ) Local $Textbox = _CRL_CreateObject($oAssembly, "System.Windows.Forms.TextBox") $Textbox.Width = 120 $Textbox.Top = 55 $Textbox.Left = 295 $Textbox.Text = "Enter Text Here ..." ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.ListView" & @CRLF ) Local $ListView = _CRL_CreateObject($oAssembly, "System.Windows.Forms.ListView") $ListView.Width = 220 $ListView.Top = 95 $ListView.Left = 295 ConsoleWrite( @CRLF & "_CRL_CreateObject System.Windows.Forms.ColumnHeader" & @CRLF ) Local $columnHeader1 = _CRL_CreateObject($oAssembly, "System.Windows.Forms.ColumnHeader") ConsoleWrite("$columnHeader1 : " & IsObj($columnHeader1) & @CRLF & @CRLF) $ListView.Columns.add($columnHeader1) ; Does not work !!! #EndRegion #Region Events 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 ) ; Make an event handler (event must be of the EventHandler type). Local $oHandler = $oHelper.MakeHandler( $pEventHandler ) $oButton1.add_Click( $oHandler ) $oButton2.add_Click( $oHandler ) #EndRegion #Region Add Controls ;$oForm.Controls.Add( $oButton1 ) ; ERR $oButton1.Parent = $oForm ; OK $oButton2.Parent = $oForm $checkbox1.Parent = $oForm $Combo.Parent = $oForm $Label.Parent = $oForm $Textbox.Parent = $oForm $ListView.Parent = $oForm #EndRegion $oForm.ShowDialog() $oForm.Dispose() EndFunc #Region EventHandler ; 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, $pData, $obj SafeArrayAccessData( $pprm, $prmData ) $vt = DllStructGetData( DllStructCreate( "word", $prmData ), 1 ) ConsoleWrite( "$vt = " & $vt & @CRLF & @CRLF ) ; EventArgs Class $pData = DllStructGetData( DllStructCreate( "ptr", $prmData + 8 ), 1 ) $obj = ObjCreateInterface( $pData, $sIID_IDispatch ) ; Convert Pointer to iDispatch SafeArrayUnaccessData( $pprm ) For $i = 0 To UBound( $aObjects ) - 1 If $obj.Equals( $aObjects[$i] ) Then ExitLoop Next If $i < UBound( $aObjects ) Then MsgBox( 0, "", $obj.ToString() ) EndIf EndFunc #EndRegion Again issues with adding controls using the .NET syntax Anyhow there are a few more hurdles to take ... like the _CRL_CreateObject( xxx, Arg1, Arg2, ...) is missing list of arguments to pass to the object's constructor. Examples : - System.Drawing.Size(130,60) - System.Drawing.Font("Times New Roman",12) Also found this was implemented on the AHK CLR : CLR_CreateObject( Assembly, sType [, Type1, Arg1, Type2, Arg2 ... ] ) (CLR) Instantiates an object of the specified type from the specified assembly. Optionally accepts a list of arguments to pass to the object's constructor. For AutoHotkey Basic, TypeN is a value from the VARENUM enumeration Again we are a few steps closer to the finish line ...1 point
-
aa2zz6, Use the line continuation operator: ;What I'd like I do Global $arr[] = [5, "1", _ "2","3", _ "4","5"] M23 Edit: It is found in the Help file under <Language Reference - Comments>.1 point
-
^^ Small remark if I may... that ConvertPtrToIDispatch() function isn't really how it should be done today. Much better would be: $obj = ObjCreateInterface($data, $sIID_IDispatch) Grrr... "nowadays".1 point
-
First post here, please be gentle I've spent hours and hours trying to figure out this puzzle. It's impossible to google for because I don't know the precise terminology to use. All msdn links I find are either dead or has been removed like 10 years ago. Here is a tiny code example: $objWMIService = ObjGet("winmgmts:") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface Where Name like '%intel%'") For $objItem In $colItems ConsoleWrite($objItem.PacketsPersec & @CRLF) Next In that example I'm using the asterix * and it retrieves all properties in the "Win32_PerfRawData_Tcpip_NetworkInterface" class. But I'm only utilizing "PacketsPersec" in the example. How could I enumerate all the properties without defining their names beforehand? (FYI, I do know their names, but the script doesn't know the names) In other words; how can I use "SELECT *" on any class and output all properties, one by one? Without having to manually specify each property with $objItem.<propertyname> ? As comparison, using wmic in a cmd shell ... wmic path Win32_PerfRawData_Tcpip_NetworkInterface Where "Name like '%intel%'" get /value ...and it lists all properties in "Names=Value" manner. This is sort of the same function I'm looking for. How could I do the same in Autoit? EDIT: I cannot run a powershell or cmd to "solve" the problem. I need to find a way to do this "internally" in Autoit. I.e. by calling the WMI service directly with ObjGet(winmgmts:) or connect to the WMI system with CreateObject("WbemScripting.SWbemLocator"). Performance is a major factor.1 point
-
1 point
-
New Version: DOWNLOAD LINK EDIT: Example: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N #include <MsgBoxConstants.au3> #include "SmtpMailer.au3" #Region Example Script ;################################## ; Example Script ;################################## _Example() Func _Example() Local $sSmtpServer = "MailServer" Local $sUsername = "******" Local $sPassword = "********" Local $sFromName = "Name" Local $sFromAddress = "your@Email.Address.com" Local $sToAddress = "your@Email.Address.com" Local $sSubject = "Userinfo" Local $sBody = "Some text/html to send as body part" Local $sAttachFiles = "" Local $sCcAddress = "CCadress1@test.com" Local $sBccAddress = "BCCadress1@test.com" Local $sImportance = "Normal" Local $iIPPort = 25 Local $bSSL = False ; Local $iIPPort = 465 ; GMAIL port used for sending the mail ; Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using https Local $bIsHTMLBody = False Local $iDSNOptions = $g__cdoDSNDefault Local $sResultDescription = _SMTP_SendEmail($sSmtpServer, $sUsername, $sPassword, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions) If Not @error Then Return SetError(@error, @extended, $sResultDescription) ElseIf @error = $SMTP_ERR_SEND Then ConsoleWrite("! Number: " & _SMTP_COMErrorHexNumber() & " UDF Script Line: " & _SMTP_ComErrorScriptLine() & " Description:" & _SMTP_COMErrorDescription() & @LF) MsgBox($MB_ICONERROR, "Error sending email", "_SMTP_SendEmail()" & @CRLF & "Error code: $SMTP_ERR_SEND" & @CRLF & "Description:" & $sResultDescription & @CRLF & "COM Error Number: "& _SMTP_COMErrorHexNumber()) Return SetError($SMTP_ERR_SEND, 0, 0) Else Return SetError(@error, @extended, 0) EndIf EndFunc ;==>_Example #EndRegion Example Script BE CAREFULL THERE IS MANY SCRIPT BREAKING CHANGES Read carefull changelog before you use it.1 point