Leaderboard
Popular Content
Showing content with the highest reputation on 12/23/2011 in all areas
-
Help with asm
jvanegmond and one other reacted to jchd for a topic
Granted, getting better is a nice goal. I look at attempts of achieving "top notch" optimization as now essentially useless. It was possible at some time to perform register coloring, loop unrolling and such optimizations "by hand". Today's CPUs and architectures are way too complex and varied for a human brain to apply effective optimizations on anything but very very small code sources. Even a small critical routine you want/need to optimize is now out of reach in practice. The result you'll get will highly depend on the exact processor running your handcrafted code. What you believe is a smart optimization will break the low-level MIPS pipeline in a different processor. You can't even make two piles: AMD and Intel. Subtle or large changes in different series or successive CPUs from a given brand can give highly varying result on integer, cache, branching prediction, rearrangement, pipeline, FP. So unless you target a very precise hardware, you can't squeaze the best speed from seemingly comparable stock platforms. Even understanding _all_ the published fine details that needs mastering for a given platform is a daunting task, if not plain impossible. Algorithms for low-level instructions rearrangement are not publicized and they play a significant role in speed, for a selected instruction mix based on criterions you don't know. That said, there's another point I think you miss. Compilers are also getting much better and the best ones are able to select better optimizations when informed they target a specific platform, using cryptic options and online directives. They do that routinely and evolve as new processor architectures appear. Then there's another, more important, point. If we start talking at a non-trivial portion of code and talk about, say, a complete significant library, then another very simple yet highly effective approach allows important speed gains. Preprocess the whole lot of individual files and compile the huge resulting source in one go. That's because good compilers (here I mean e.g. GCC & Intel C[++] compilers) are able to detect incredible very large scale optimizations on complex code that you couldn't even consider watching at once. For instance, the SQLite C source sees average increase of 5 to 10% in speed when compiled in the "amalgamated" form (single huge source) compared to separate compilation for the same platform and compile options. That can even reach 15% on some embedded platforms! This sort of "fish-eye" view and deep analysis on 10K or 100K lines of code at a time is out of question for any human brain. I certainly don't mean that learning and questionning is bad. It's just not getting rewarding and/or effective enough to try to reach "code heaven" by mere brain means, thanks to advances in hardware (faster processors, unlimited memory) and compilers' sophistication.2 points -
These two simple Functions convert from a UK formated date to a US formated date or vice versa. #include <MsgBoxConstants.au3> Example() Func Example() Local $sUKDate = @MDAY & '/' & @MON & '/' & @YEAR Local $sUSDate = @MON & '/' & @MDAY & '/' & @YEAR & ' ' & @HOUR & ':' & @MIN & ':' & @SEC MsgBox($MB_SYSTEMMODAL, '', 'Was ' & $sUKDate & ' & now it''s ' & _UKToUSDate($sUKDate) & ' in the US Format.') MsgBox($MB_SYSTEMMODAL, '', 'Was ' & $sUSDate & ' & now it''s ' & _USToUKDate($sUSDate) & ' in the UK Format.') EndFunc ;==>Example Func _UKToUSDate($sDate) ; DD/MM/YYYY >> MM/DD/YYYY Return StringRegExpReplace($sDate, '^(\d{2})\D?(\d{2})\D?(\d{4})([\d\s:]*)$', '\2/\1/\3\4') EndFunc ;==>_UKToUSDate Func _USToUKDate($sDate) ; MM/DD/YYYY >> DD/MM/YYYY Return StringRegExpReplace($sDate, '^(\d{2})\D?(\d{2})\D?(\d{4})([\d\s:]*)$', '\2/\1/\3\4') EndFunc ;==>_USToUKDate1 point
-
_Singleton() is what you're looking, read the Help file.1 point
-
Krankios, Very true. If this is the best you can think of as a present - please do NOT come back. M231 point
-
AutoIt v3.3.8.0 Released Thanks to all involved in coding and testing. Merry xmas. Download History Script Breaking Changes1 point
-
You may want to look into the excel.au3 functions a bit further. Seeing how you are using "Send" in your script your code will fail if the window is hidden.1 point
-
phanan, Rather than using Mediafire, just post the code here. But please use Code tags - put [autoit] before and [/autoit] after it. Then you get a nice scriollable box with pretty colurs like this: ; This is between code tags $sFred = "Fred"M231 point
-
Have a look at the flags in _ExcelBookOpen (hint: $fVisible)1 point
-
Ok. Perhaps I shouldn't have said that base 0 was a tally. Let's look at the theory. From other bases we can see that there should be only one character (by looking at the pattern of characters I have already said this should be zero, ofc that looks silly in practice and doesn't actually work). The positions are in increasing powers of 1 as you go to the left, and decreasing to the right. That's a rather useless thing though as 1^x == 1. Representing any decimal is therefore not possible as all powers on the right are still 1/1 = 1, so you can't represent something less than 1. 1 ^ infinity should be 1 (undefined by wolfram alpha, but log laws (inf*log(1) = inf*0) mean it could be anything, but would usually be defined as 1). From that I conclude no decimal less than 1 can be represented by base 1, so it's not a real number system. If you define it any other way (so a tally = epsilon or whatever) then it's different. It's not a numeric bases system in the same way roman numerals aren't.1 point
-
Greetings KaFu You can get most* of the icons from the notification area using shared memory code. The traydata struct in the TBBUTTON/TBBUTTONINFO structs Param element has a handle to the toolbar button icon. The traydata struct is undocumented but works in XP, Vista and Win 7 x86/x64 I use this in my _RefreshNotificationAreaIcons and _RefreshTrayIcon() UDFs The SysTray UDF only retrieves the owner window handle from the traydata struct. Get and use Imagelist From Another Process http://www.xtremevbtalk.com/showthread.php?t=128730 I ran the above struct code, and it does return some systray (XP) imagelist info (image count, icon size, etc.). The bitmap and memdc handles as mentioned are not accessible outside of the explorer process. The imagelist struct is different from the standard imagelist, _GUICtrlToolbar_GetImageList returns a handle, but ImageList_GetImageCount() returns 0. *As pointed out in that vb forum, some apps that frequently update their icons (temp, cpu use, etc.) will update the icon image in the notification areas imagelist with Shell_NotifyIcon + NIM_MODIFY, then destroy the icon handle, so the notification area imagelist has the current icon, but the handle in the traydata struct is not valid. Taskmgr replacements Process Explorer and Process Hacker 2 have process history tray icons that return invalid icon handles. I wrote some tray icon retrieval code a few years back, here's an updated example. For XP/2003,Vista/2008,Win7/2008R2 x86/x64 ;coded by rover 2k11 #NoTrayIcon #Include <WinAPIEx.au3> #include <WinAPI.au3> #include <Process.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <Constants.au3> #Include <APIConstants.au3> #include <WindowsConstants.au3> #Include <ToolBarConstants.au3> #Include <ProcessConstants.au3> #include <MemoryConstants.au3> Opt("MustDeclareVars", 1) Global Const $PROCESS_ACCESS = BitOR($PROCESS_VM_OPERATION, $PROCESS_VM_READ) Global $iTbar = 0 Global $hOwnerWin, $hTrayWnd, $hTrayNotifyWnd, $hSysPager, $hToolbar, _ $iDLLUser32 = DllOpen("user32.dll"), $iDLLKrnl32 = DllOpen("kernel32.dll"), _ $tTBBUTTON, $pTBBUTTON, $iTBBUTTON, $tTRAYDATA, $pTRAYDATA, $iTRAYDATA, _ $iImg = 0, $iIdx = 0, $iCount, $iPIDExp, $hProcess, $pAddress, $iPID, $aRet, $sRet, $hIconTray, $hIcon $hTrayWnd = WinGetHandle("[CLASS:Shell_TrayWnd]") $hTrayNotifyWnd = ControlGetHandle($hTrayWnd, "", "[CLASS:TrayNotifyWnd]") $hSysPager = ControlGetHandle($hTrayNotifyWnd, "", "[CLASS:SysPager]") $hToolbar = ControlGetHandle($hSysPager, "", "[CLASS:ToolbarWindow32; INSTANCE:1]");User Promoted Notification Area/Notification Area/SysTray Switch @OSVersion Case "WIN_2008R2", "WIN_7" Switch $iTbar Case 1 ;Overflow Notification Area $hToolbar = ControlGetHandle(WinGetHandle("[CLASS:NotifyIconOverflowWindow]"), "", "[CLASS:ToolbarWindow32; INSTANCE:1]") Case 2 ;System Promoted Notification Area $hToolbar = ControlGetHandle($hTrayNotifyWnd, "", "[CLASS:ToolbarWindow32; INSTANCE:2]") EndSwitch EndSwitch $tTBBUTTON = DllStructCreate("int Bitmap;int Command;byte State;byte Style;align;dword_ptr Param;int_ptr String") $pTBBUTTON = DllStructGetPtr($tTBBUTTON) $iTBBUTTON = DllStructGetSize($tTBBUTTON) $tTRAYDATA = DllStructCreate("hwnd hwnd;uint uID;uint uCallbackMessage;dword Reserved[2];ptr hIcon") $pTRAYDATA = DllStructGetPtr($tTRAYDATA) $iTRAYDATA = DllStructGetSize($tTRAYDATA) $iPIDExp = WinGetProcess($hToolbar) If @error Or $iPIDExp = -1 Then exit $aRet = DllCall($iDLLKrnl32, "ptr", "OpenProcess", "dword", _ $PROCESS_ACCESS, "int", 0, "int", $iPIDExp) If @error Or $aRet[0] = 0 Then Exit $hProcess = $aRet[0] $aRet = DllCall($iDLLUser32, "lparam", "SendMessageW", "hwnd", _ $hToolbar, "int", $TB_BUTTONCOUNT, "wparam", 0, "lparam", 0) If @error Or $aRet[0] < 1 Then DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProcess) Exit EndIf $iCount = $aRet[0] - 1 $aRet = DllCall($iDLLKrnl32, "ptr", "VirtualAllocEx", "ptr", $hProcess, "ptr", 0, "ulong_ptr", _ $iTBBUTTON, "dword", BitOR($MEM_RESERVE, $MEM_COMMIT), "dword", $PAGE_READWRITE) If @error Or $aRet[0] = 0 Then DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProcess) Exit EndIf $pAddress = $aRet[0] GUICreate("Notification Icons", 600, 600) GUISetBkColor(0x494949) Global $hListView = GUICtrlCreateListView("", 2, 2, 596, 596) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) Global $hImage = _GUIImageList_Create(16,16,5,5) _GUICtrlListView_SetImageList($hListView, $hImage, 1) _GUICtrlListView_AddColumn($hListView, "Tray", 38) _GUICtrlListView_AddColumn($hListView, "Proc", 38) _GUICtrlListView_AddColumn($hListView, "Process", 138) _GUICtrlListView_AddColumn($hListView, "Module", 138) _GUICtrlListView_SetColumnWidth($hListView, 3, $LVSCW_AUTOSIZE_USEHEADER) GUISetState() For $iID = 0 To $iCount If IsHWnd($hToolbar) = False Then ExitLoop $aRet = DllCall($iDLLUser32, "lparam", "SendMessageW", "hwnd", $hToolbar, _ "int", $TB_GETBUTTON, "wparam", $iID, "lparam", $pAddress) If @error Or $aRet[0] <> 1 Then ContinueLoop $aRet = DllCall($iDLLKrnl32, "int", "ReadProcessMemory", "ptr", $hProcess, _ "ptr", $pAddress, "ptr", $pTBBUTTON, "ulong_ptr", $iTBBUTTON, "ulong_ptr*", -1) If @error Or $aRet[5] <> $iTBBUTTON Then ContinueLoop ;If BitAND(DllStructGetData($tTBBUTTON, "State"), $TBSTATE_HIDDEN) = $TBSTATE_HIDDEN Then ContinueLoop $aRet = DllCall($iDLLKrnl32, "int", "ReadProcessMemory", "ptr", $hProcess, _ "dword_ptr", DllStructGetData($tTBBUTTON, "Param"), "ptr", $pTRAYDATA, "ulong_ptr", $iTRAYDATA, "ulong_ptr*", -1) If @error Or $aRet[5] <> $iTRAYDATA Then ContinueLoop $hOwnerWin = DllStructGetData($tTRAYDATA, 1) If @error Or $hOwnerWin = 0 Then ContinueLoop $iPID = WinGetProcess($hOwnerWin) If @error Or $iPID = -1 Then ContinueLoop $hIconTray = DllStructGetData($tTRAYDATA, 5) ;returned icon handles shared $sRet = "" If Not _IsIconHandle($hIconTray, $sRet) Then ;ConsoleWrite('!VarGetType($hIconTray) = ' & VarGetType($hIconTray) & @CRLF) If IsPtr($hIconTray) Then $hIconTray = _WinAPI_Create32BitHICON($hIconTray) ;some icons like HDDLife's temp icons return an invalid icon handle, and won't display, but will when formatted by _WinAPI_Create32BitHICON If Not _IsIconHandle($hIconTray, $sRet) Then $hIconTray = _GetTrayIconHandle($hOwnerWin) ConsoleWrite("- Invalid Icon handle: OwnerWin: " & _WinAPI_GetClassName($hOwnerWin) & " Process Name: " & _ProcessGetName($iPID) & @crlf) EndIf EndIf ;$hIconTray = _WinAPI_CopyImage($hIconTray, $IMAGE_ICON, 16, 16) _GUIImageList_ReplaceIcon($hImage, -1, $hIconTray) $hIcon = _WinAPI_ShellExtractAssociatedIcon(_WinAPI_GetProcessFileName($iPID), 1) $iImg = _GUIImageList_ReplaceIcon($hImage, -1, $hIcon) _GUICtrlListView_InsertItem($hListView, "", -1, $iImg-1) _GUICtrlListView_AddSubItem($hListView, $iIdx, "", 1, $iImg) _GUICtrlListView_AddSubItem($hListView, $iIdx, _ProcessGetName($iPID), 2) If $sRet = "" Then $sRet = _WinAPI_GetProcessFileName($iPID) _GUICtrlListView_AddSubItem($hListView, $iIdx, $sRet, 3) $iIdx += 1 ;ToolTip(_WinAPI_GetClassName($hOwnerWin), 1030, 850, $sRet, $hIconTray, 5) ;Sleep(500) _WinAPI_DestroyIcon($hIcon) _WinAPI_DestroyIcon($hIconTray) ;does not destroy traydata handles Next DllCall($iDLLKrnl32, "int", "VirtualFreeEx", "ptr", $hProcess, "ptr", $pAddress, "ulong_ptr", 0, "dword", $MEM_RELEASE) DllCall($iDLLKrnl32, "int", "CloseHandle", "ptr", $hProcess) DllClose($iDLLUser32) DllClose($iDLLKrnl32) ToolTip("") While GUIGetMsg() <> -3 WEnd _GUIImageList_Destroy($hImage) Exit Func _GetTrayIconHandle($hWnd, $hDLLUser32 = "User32.dll") If Not IsHWnd($hWnd) Then Return SetError(1, 1, -1) Local $iPID, $ParentPID, $aWinList $hIcon = _GetIcon($hWnd, $hDLLUser32) If Not @error And $hIcon <> -1 Then Return SetError(0, 0, $hIcon) $ParentPID = WinGetProcess($hWnd) If @error Or $ParentPID = -1 Then Return SetError(2, 2, -1) $aWinList = WinList() For $i = 1 to $aWinList[0][0] $iPID = WinGetProcess($aWinList[$i][1]) If @error Or $iPID = -1 Then ContinueLoop If $iPID = $ParentPID Then $hIcon = _GetIcon($aWinList[$i][1], $hDLLUser32) If Not @error And $hIcon <> -1 Then Return SetError(0, 0, $hIcon) EndIf Next Return SetError(2, 2, -1) EndFunc ;modified from ModernMenu Win2Tray - by Holger Kotsch Func _GetIcon(ByRef $hWnd, $hDLLUser32 = "User32.dll") If Not IsHWnd($hWnd) Then Return SetError(1, 1, -1) Local Const $GCL_HICON = -14 Local Const $GCL_HICONSM = -34 Local $hIcon $hIcon = _SendMessage($hWnd, $WM_GETICON, 2, 0) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _SendMessage($hWnd, $WM_GETICON, 0, 0) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _WinAPI_GetClassLongEx($hWnd, $GCL_HICONSM) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) $hIcon = _WinAPI_GetClassLongEx($hWnd, $GCL_HICON) If Not @error And _IsIconHandle($hIcon, $sRet) = True Then Return SetError(0, 0, Ptr($hIcon)) Return SetError(2, 2, -1) EndFunc Func _IsIconHandle($hIcon, ByRef $sMod) ;rover 2k11 Local $aRet Switch @OSVersion Case "WIN_2008R2", "WIN_7", "WIN_2008", "WIN_VISTA" $aRet = _WinAPI_GetIconInfoEx($hIcon) If @error Then Return SetError(1, 1, False) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", $aRet[3]) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", $aRet[4]) If $aRet[0] = 0 Then Return SetError(2, 2, False) $sMod = $aRet[6] Return SetError(0, 0, True) Case "WIN_2003", "WIN_XP" Local $tIconInfo = DllStructCreate("int fIcon;int xHotspot;int yHotspot;ptr hbmMask;ptr hbmColor") Local $aRet = DllCall("User32.dll", "int", "GetIconInfo", "ptr", $hIcon, "ptr", DllStructGetPtr($tIconInfo)) If @error Or UBound($aRet) <> 3 Or $aRet[0] = 0 Then Return SetError(1, 1, False) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", DllStructGetData($tIconInfo, 4)) DllCall("gdi32.dll", "bool", "DeleteObject", "ptr", DllStructGetData($tIconInfo, 5)) If Not DllStructGetData($tIconInfo, 1) Then Return SetError(2, 2, False) Return SetError(0, 0, True) EndSwitch EndFunc1 point
-
Active Directory Scripts
JoshuaBarnette reacted to Johny Clelland for a topic
Significent, Apologies for taking so long to get back to you. This error was caused by a change in ADFunctions where some functions changed from requiring SamAccountNames to FQDNs. Simple fix is to change the line that calls _ADGetGroupMembers to this; If _ADGetGroupMembers($Members, _ADSamAccountNametoFQDN($GroupName), 0) == 1 Then That sorts it out :-) Hope this helps, Johny.1 point