Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AHK Functions :: InCache() - Cache List of Recent Items


  • Please log in to reply
172 replies to this topic
cherno
  • Guests
  • Last active:
  • Joined: --
Is there any errorlevel that can be used with ShellFileOperation() ? (ex. If 'Cancel' was pressed)

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
SKAN's function returns the address of the fAnyOperationsAborted member of the SHFILEOPTSTRUCT Structure. You can use this to check if any operations were aborted, and if so use the error code to determine what the problem was.

I have modified the function slightly so you can see what I mean (changes in red)

SetBatchLines -1
SetWorkingDir, %A_ScriptDir%

imgPath := A_Temp . "orary Internet Files"
Loop, %imgPath%\*.gif, 0 ,1
     Source .= A_LoopFileLongPath "|"

Target := A_ScriptDir "\Gif_Files"

flags := ( FOF_RENAMEONCOLLISION := 0x8 ) | ( FOF_NOCONFIRMMKDIR := 0x200 )

[color=red]If ( ErrorCode := [/color]ShellFileOperation( 0x2, Source, Target, flags )[color=red] )[/color] ; the variable "ErrorCode" will hold the error value if there was one
[color=red]   MsgBox, Error Code "%ErrorCode%".  Check http://msdn.microsoft.com/en-us/library/ms681381`%28v=VS.85`%29.aspx for explanation of the error code.[/color]

Return


ShellFileOperation( fileO=0x0, fSource="", fTarget="", flags=0x0, ghwnd=0x0 )     {

 If ( SubStr(fSource,0) != "|" )
      fSource := fSource . "|"

 If ( SubStr(fTarget,0) != "|" )
      fTarget := fTarget . "|"

 fsPtr := &fSource
 Loop, % StrLen(fSource)
  If ( *(fsPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, fsPtr+(A_Index-1), Int,1, UChar,0 )

 ftPtr := &fTarget
 Loop, % StrLen(fTarget)
  If ( *(ftPtr+(A_Index-1)) = 124 )
      DllCall( "RtlFillMemory", UInt, ftPtr+(A_Index-1), Int,1, UChar,0 )

 VarSetCapacity( SHFILEOPSTRUCT, 30, 0 )                 ; Encoding SHFILEOPSTRUCT
 NextOffset := NumPut( ghwnd, &SHFILEOPSTRUCT )          ; hWnd of calling GUI
 NextOffset := NumPut( fileO, NextOffset+0    )          ; File operation
 NextOffset := NumPut( fsPtr, NextOffset+0    )          ; Source file / pattern
 NextOffset := NumPut( ftPtr, NextOffset+0    )          ; Target file / folder
 NextOffset := NumPut( flags, NextOffset+0, 0, "Short" ) ; options

 [color=red]ret := [/color]DllCall( "Shell32\SHFileOperationA", UInt,&SHFILEOPSTRUCT )  ; store the return value of the function (error code)
 
 Return NumGet( NextOffset+0 )[color=red] ? ret : 0[/color] ; if the fAnyOperationsAborted member was true, return the error code, otherwise return 0.
}


cherno
  • Guests
  • Last active:
  • Joined: --

SKAN's function returns the address of the fAnyOperationsAborted member of the SHFILEOPTSTRUCT Structure. You can use this to check if any operations were aborted, and if so use the error code to determine what the problem was.

I have modified the function slightly so you can see what I mean (changes in red)


Many thanks! :D

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

Dear Friends, :)

Space()

Space(Width)
{
Loop,%Width%
Space=% Space Chr(32)
Return Space
}


this is a function with similar capabilities, yet more flexible, since it allows to specify any ansi char and its faster, since it uses less operations (eg no loop)

dup( length, char = " " )
{
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}

per default it uses a space as the fillchar

greets
dR

Enter_User_Name_Here
  • Members
  • 35 posts
  • Last active: Jan 19 2012 07:40 PM
  • Joined: 18 Apr 2010

I will be glad if this code is optimised..

LDOM(TimeStr="") {
  If TimeStr=
     TimeStr = %A_Now%
  StringLeft Date,TimeStr,6 ; YearMonth
  Date1 = %Date%
  Date1+= 31,D              ; A day in next month
  StringLeft Date1,Date1,6  ; YearNextmonth
  Date1-= %Date%,D          ; Difference in days
  Return Date1
}


Dear Laszlo, :D

Brilliant! You always amaze me .. I would have never thought this way.
I wrote LDOM() 10 years before (in Foxpro) for a Payroll Software.
What I have presented here is a optimised version. ( I thought so! )

In the original function, I start with day 1 (for the given date) and
loop till the month changes and then break.. :shock:

I have to change the way I envision, I guess! :D

Thank you .. Regards, :)



Date1+= 31,D              ; A day in next month
Won't this break if you are at the end of Jan (29, 30, 31)? Won't you push on in to March?

SKAN
  • Administrators
  • 9114 posts
  • Last active:
  • Joined: 26 Dec 2005

Date1+= 31,D              ; A day in next month
Won't this break if you are at the end of Jan (29, 30, 31)? Won't you push on in to March?


It will not.. It is Laszlo's code, I remind you.
The following part takes care of it:
StringLeft Date,TimeStr,6 ; YearMonth


SKAN
  • Administrators
  • 9114 posts
  • Last active:
  • Joined: 26 Dec 2005

dup( length, char = " " )
{
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


I tried that a long time ago, and it worked incorrectly for length < 3
.. and then Lexikos clarified me about VarSetCapacity()

You need to add a pair of additional VarSetCapacity()

dup( length, char = " " )
{
[color=red]   VarSetCapacity( dup,64 ), VarSetCapacity( dup,0 )[/color]
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}

I updated my Replicate() function as follows:

Replicate( Chr=" ", X=1 ) {
 Return VarSetCapacity( V, VarSetCapacity(V,VarSetCapacity(V,64)>>32)+X, Asc(Chr) ) ? V :
}

MsgBox, % Replicate( "/", 90 ) ; Example


derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

I tried that a long time ago, and it worked incorrectly for length < 3
.. and then Lexikos clarified me about VarSetCapacity()

You need to add a pair of additional VarSetCapacity()

dup( length, char = " " )
{
[color=red]   VarSetCapacity( dup,64 ), VarSetCapacity( dup,0 )[/color]
   return ( length > 0 && VarSetCapacity( dup, length, asc(char) ) ) ? dup : false
}


Yeah well, i tested only with 5 chars and u were perfectly right with lengths less than 3, however there is a different solution, which works without the need for two additional varsetcapacitys, so if you're for short codes this one's for you:

dup(l,c=" ")
{
return l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _:
}

edit

this one even repeats strings when passed as c
dup(l,c=" ") {
	return StrLen(c)=1 ? l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _::RegExReplace(dup(l)," ",c)
}

edit II

this function should be named String instead of dup
greets
dR

SKAN
  • Administrators
  • 9114 posts
  • Last active:
  • Joined: 26 Dec 2005

dup(l,c=" ")
{
return l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _:
}


Nice! :D

Lexikos
  • Administrators
  • 9451 posts
  • Last active:
  • Joined: 17 Oct 2006
Since VarSetCapacity fills bytes, not characters, that method won't work in Unicode builds. See infogulch's post and my responses.

derRaphael
  • Members
  • 872 posts
  • Last active: Mar 19 2013 04:42 PM
  • Joined: 23 Nov 2007

Since VarSetCapacity fills bytes, not characters, that method won't work in Unicode builds. See infogulch's post and my responses.


even not this one?

dup(l,c=" ") {
	return StrLen(c)=1 ? l>0&&(VarSetCapacity(_,l,asc(c))|Numput(0,_,l,"UChar"))? _::RegExReplace(dup(l)," ",c)
}


or does it fail due to the strlen() ?

Lexikos
  • Administrators
  • 9451 posts
  • Last active:
  • Joined: 17 Oct 2006
It relies on VarSetCapacity either way and will therefore fail on Unicode builds regardless of how long 'c' is.

djmorgan911
  • Members
  • 1 posts
  • Last active: Nov 24 2010 02:41 PM
  • Joined: 26 Aug 2010
In regards to LDOM, is there a way to figure out what the year of the last month is? Example: I run a set of reports each month. They are run using last months dates. So if I automate this report to run in Feb, then last months year is the same as the current year but if I run it in Jan, I need it to figure out that last month was last year not the current year.

Hope I have made sense!

SKAN
  • Administrators
  • 9114 posts
  • Last active:
  • Joined: 26 Dec 2005

I need it to figure out that last month was last year not the current year


somedate=20100826

MsgBox, % YearOfPreviousMonth( somedate )

YearOfPreviousMonth( date ) {
 date += 0,D
 date := SubStr(date,1,6 )
 date += -1,D
 Return substr( date,1,4 )
}


SKAN
  • Administrators
  • 9114 posts
  • Last active:
  • Joined: 26 Dec 2005

PE_FunctionExports()

Returns a linefeed-delimited-list of 'Exported Function Names' found in a Portable Executable file.

Usage Example:

MsgBox, % PE_FunctionExports( "[color=red]shell32.dll[/color]" )

Output of above call:
Activate_RunDLL
AppCompat_RunDLLW
CDefFolderMenu_Create
CDefFolderMenu_Create2
CallCPLEntry16
CheckEscapesA
CheckEscapesW
CommandLineToArgvW
Control_FillCache_RunDLL
Control_FillCache_RunDLLA
Control_FillCache_RunDLLW
Control_RunDLL
Control_RunDLLA
Control_RunDLLAsUserW
Control_RunDLLW
DAD_AutoScroll
DAD_DragEnterEx
DAD_DragEnterEx2
DAD_DragLeave
DAD_DragMove
DAD_SetDragImage
DAD_ShowDragImage
DllCanUnloadNow
DllGetClassObject
DllGetVersion
DllInstall
DllRegisterServer
DllUnregisterServer
DoEnvironmentSubstA
DoEnvironmentSubstW
DragAcceptFiles
DragFinish
DragQueryFile
DragQueryFileA
DragQueryFileAorW
DragQueryFileW
DragQueryPoint
DriveType
DuplicateIcon
ExtractAssociatedIconA
ExtractAssociatedIconExA
ExtractAssociatedIconExW
ExtractAssociatedIconW
ExtractIconA
ExtractIconEx
ExtractIconExA
ExtractIconExW
ExtractIconResInfoA
ExtractIconResInfoW
ExtractIconW
ExtractVersionResource16W
FindExeDlgProc
FindExecutableA
FindExecutableW
FreeIconList
GetFileNameFromBrowse
ILAppendID
ILClone
ILCloneFirst
ILCombine
ILCreateFromPath
ILCreateFromPathA
ILCreateFromPathW
ILFindChild
ILFindLastID
ILFree
ILGetNext
ILGetSize
ILIsEqual
ILIsParent
ILLoadFromStream
ILRemoveLastID
ILSaveToStream
InternalExtractIconListA
InternalExtractIconListW
IsLFNDrive
IsLFNDriveA
IsLFNDriveW
IsNetDrive
IsUserAnAdmin
OpenAs_RunDLL
OpenAs_RunDLLA
OpenAs_RunDLLW
OpenRegStream
Options_RunDLL
Options_RunDLLA
Options_RunDLLW
PathCleanupSpec
PathGetShortPath
PathIsExe
PathIsSlowA
PathIsSlowW
PathMakeUniqueName
PathProcessCommand
PathQualify
PathResolve
PathYetAnotherMakeUniqueName
PickIconDlg
PifMgr_CloseProperties
PifMgr_GetProperties
PifMgr_OpenProperties
PifMgr_SetProperties
PrintersGetCommand_RunDLL
PrintersGetCommand_RunDLLA
PrintersGetCommand_RunDLLW
ReadCabinetState
RealDriveType
RealShellExecuteA
RealShellExecuteExA
RealShellExecuteExW
RealShellExecuteW
RegenerateUserEnvironment
RestartDialog
RestartDialogEx
SHAddFromPropSheetExtArray
SHAddToRecentDocs
SHAlloc
SHAllocShared
SHAppBarMessage
SHBindToParent
SHBrowseForFolder
SHBrowseForFolderA
SHBrowseForFolderW
SHCLSIDFromString
SHChangeNotification_Lock
SHChangeNotification_Unlock
SHChangeNotify
SHChangeNotifyDeregister
SHChangeNotifyRegister
SHChangeNotifySuspendResume
SHCloneSpecialIDList
SHCoCreateInstance
SHCreateDirectory
SHCreateDirectoryExA
SHCreateDirectoryExW
SHCreateFileExtractIconW
SHCreateLocalServerRunDll
SHCreateProcessAsUserW
SHCreatePropSheetExtArray
SHCreateQueryCancelAutoPlayMoniker
SHCreateShellFolderView
SHCreateShellFolderViewEx
SHCreateShellItem
SHCreateStdEnumFmtEtc
SHDefExtractIconA
SHDefExtractIconW
SHDestroyPropSheetExtArray
SHDoDragDrop
SHEmptyRecycleBinA
SHEmptyRecycleBinW
SHEnableServiceObject
SHEnumerateUnreadMailAccountsW
SHExtractIconsW
SHFileOperation
SHFileOperationA
SHFileOperationW
SHFindFiles
SHFind_InitMenuPopup
SHFlushClipboard
SHFlushSFCache
SHFormatDrive
SHFree
SHFreeNameMappings
SHFreeShared
SHGetAttributesFromDataObject
SHGetDataFromIDListA
SHGetDataFromIDListW
SHGetDesktopFolder
SHGetDiskFreeSpaceA
SHGetDiskFreeSpaceExA
SHGetDiskFreeSpaceExW
SHGetFileInfo
SHGetFileInfoA
SHGetFileInfoW
SHGetFolderLocation
SHGetFolderPathA
SHGetFolderPathAndSubDirA
SHGetFolderPathAndSubDirW
SHGetFolderPathW
SHGetIconOverlayIndexA
SHGetIconOverlayIndexW
SHGetImageList
SHGetInstanceExplorer
SHGetMalloc
SHGetNewLinkInfo
SHGetNewLinkInfoA
SHGetNewLinkInfoW
SHGetPathFromIDList
SHGetPathFromIDListA
SHGetPathFromIDListW
SHGetRealIDL
SHGetSetFolderCustomSettingsW
SHGetSetSettings
SHGetSettings
SHGetShellStyleHInstance
SHGetSpecialFolderLocation
SHGetSpecialFolderPathA
SHGetSpecialFolderPathW
SHGetUnreadMailCountW
SHHandleUpdateImage
SHHelpShortcuts_RunDLL
SHHelpShortcuts_RunDLLA
SHHelpShortcuts_RunDLLW
SHILCreateFromPath
SHInvokePrinterCommandA
SHInvokePrinterCommandW
SHIsFileAvailableOffline
SHLimitInputEdit
SHLoadInProc
SHLoadNonloadedIconOverlayIdentifiers
SHLoadOLE
SHLockShared
SHMapIDListToImageListIndexAsync
SHMapPIDLToSystemImageListIndex
SHMultiFileProperties
SHObjectProperties
SHOpenFolderAndSelectItems
SHOpenPropSheetW
SHParseDisplayName
SHPathPrepareForWriteA
SHPathPrepareForWriteW
SHPropStgCreate
SHPropStgReadMultiple
SHPropStgWriteMultiple
SHQueryRecycleBinA
SHQueryRecycleBinW
SHReplaceFromPropSheetExtArray
SHRestricted
SHRunControlPanel
SHSetInstanceExplorer
SHSetLocalizedName
SHSetUnreadMailCountW
SHShellFolderView_Message
SHSimpleIDListFromPath
SHStartNetConnectionDialogW
SHTestTokenMembership
SHUnlockShared
SHUpdateImageA
SHUpdateImageW
SHUpdateRecycleBinIcon
SHValidateUNC
SheChangeDirA
SheChangeDirExA
SheChangeDirExW
SheChangeDirW
SheConvertPathW
SheFullPathA
SheFullPathW
SheGetCurDrive
SheGetDirA
SheGetDirExW
SheGetDirW
SheGetPathOffsetW
SheRemoveQuotesA
SheRemoveQuotesW
SheSetCurDrive
SheShortenPathA
SheShortenPathW
ShellAboutA
ShellAboutW
ShellExec_RunDLL
ShellExec_RunDLLA
ShellExec_RunDLLW
ShellExecuteA
ShellExecuteEx
ShellExecuteExA
ShellExecuteExW
ShellExecuteW
ShellHookProc
ShellMessageBoxA
ShellMessageBoxW
Shell_GetCachedImageIndex
Shell_GetImageLists
Shell_MergeMenus
Shell_NotifyIcon
Shell_NotifyIconA
Shell_NotifyIconW
SignalFileOpen
StrChrA
StrChrIA
StrChrIW
StrChrW
StrCmpNA
StrCmpNIA
StrCmpNIW
StrCmpNW
StrCpyNA
StrCpyNW
StrNCmpA
StrNCmpIA
StrNCmpIW
StrNCmpW
StrNCpyA
StrNCpyW
StrRChrA
StrRChrIA
StrRChrIW
StrRChrW
StrRStrA
StrRStrIA
StrRStrIW
StrRStrW
StrStrA
StrStrIA
StrStrIW
StrStrW
WOWShellExecute
Win32DeleteFile
WriteCabinetState

The Function:
PE_FunctionExports( PEFile ) { ; [color=black]Lists Exported Functions/[/color][color=red] Comp@t: WIN32_NT +AHK +LA +LW[/color]
;[color=indigo]By SKAN[/color] www.autohotkey.com/forum/viewtopic.php?p=379086#379086 [color=#808080]CD:20100824/LM:20100825[/color]
 VarSetCapacity( $LI,48,0 ), DllCall( "ImageHlp\MapAndLoad", A_IsUnicode ? "AStr" 
                                      : "Str",PEFile, Int,0, UInt,&$LI, Int,1, Int,1 )
 nPtr := DllCall( "ImageHlp\ImageRvaToVa", UInt,Numget( $LI,12 ), UInt,Numget( $LI,08 )
       , UInt, NumGet( ( P := DllCall( "ImageHlp\ImageDirectoryEntryToData", UInt
       , NumGet( $LI,8 ), Int,0, UShort,0, UIntP,nSz )) + 12 ), UInt,0 )
 VarSetCapacity( Var,1024,0 ), VarSetCapacity( List,10240,0 )
 IfEqual,nPtr,0, Return SubStr( DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI ), 0,0 )
 Loop % NumGet( P+24 ) + 1
  A_IsUnicode ? Var := DllCall( "MulDiv", Int,nPtr, Int,1, Int,1, AStr )
                : DllCall( "lstrcpy", Str,Var, UInt,nPtr )
, nPtr := nPtr+StrLen( Var )+1,  List .= "`n" Var, A_Index=1 ? Omit := StrLen( Var )+2 :
 StringTrimLeft, List, List, %Omit%
 DllCall( "ImageHlp\UnMapAndLoad", UInt,&$LI )
 Return List
}

Demo : Crazy Scripting : WinAPI Listing [New Version]