Welp, I can't quite figure out how to make use of A_LastError when the script is being crashed by the DllCall. I tried an OnExit, just in case that can still be executed. I've tried putting try in there, both
and within the function itself when it sets the variables, but that doesn't prevent the crashing. (Not shown in the code below, because I guess that prevents any returns in the GUI of the script..)
As far as I know, I do keep overwriting the variable with the next file in my loop. Here's my current code, and still it's just that one file amongst all my Google Drive folders giving me a problem. There may be some code unnecessary to share here; being dragged out of the house shortly so don't quite have time to filter it out, but will do so later. The scrolling stuff I suppose is unnecessary, but I don't want to break the script with any function calls missing. The !5 is meant to diagnose in my attempt to capture A_LastError, but I couldn't figure it out like I said.
Code: Select all
^0::
Gui, New
Gui, Add, Edit, vSearch w500
Gui, Add, Button, vButton x+0 gSearch, Search
;Gui, Add, Text, x0 y1920, %A_Space%
Gui, Show, % "x0 y0 h" A_ScreenHeight - 64, Search
WinGetPos,,,,Height, Search
WinMove, Search,,,,,% Height+1
WinMove, Search,,,,,% Height
return
Search:
Gui, Submit, NoHide
StringSplit, Sea, Search, %A_Space%
resultsDesc:="",results:=[] ; [] for results?
Loop, Files, C:\Users\%A_UserName%\Google Drive\*, R
{
; Progress up to 4454 files. May as well make it 4500 files to count through
fileThatBreaksThingsFullPath:="Censored.pdf"
If (A_LoopFileFullPath=fileThatBreaksThingsFullPath) ; this file breaks the dll
continue
If (A_LoopFileExt=".nds")
continue
ExtractText(var,A_LoopFileFullPath)
count:=0
Loop % Sea0 ; Sea?
{
RegExReplace(var,"i)" sea%A_Index%,,c)
count:=c * (count?count:1) ; gives weight to the count
}
;MsgBox % count
If count
{
match++
results["count" match]:=count
results["file" match]:=A_LoopFileFullPath
Gui, Add, Text, xs Section, % results[lowest]
sink:=results["file" match]
Gui, Add, Text, gOpenEarly x50 ys vlink%match%, % sink
UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
WinGetPos,,,,Height, Search
WinMove, Search,,,,,% Height+1
WinMove, Search,,,,,% Height
; Gui, Show, % "x0 y0 h" A_ScreenHeight - 20
}
}
peel:=1, duplicate:=[]
For key, value in results
duplicate[key]:=value
Gui, Destroy
Gui, New
Gui, Default
Gui, Add, Edit, vSearch w500, %Search%
Gui, Add, Button, vButton x+0 gSearch, Search
While peel
{
old_value:=0
For key, value in results
If InStr(key,"count")
If (value>old_value)
lowest:=key, old_value:=value
Gui, Add, Text, xs Section, % results[lowest]
link:=results[f:="file" n:=SubStr(lowest,6)]
Gui, Add, Text, gOpen x50 ys vlink%n%, % link
results.Delete(lowest)
results.Delete(f)
peel:=0
For key, value in results
peel++
}
var:="", results:=""
;MsgBox % resultsDesc
Gui, Show, % "x0 y0 h" A_ScreenHeight - 64, Search
WinGetPos,,,,Height, Search
WinMove, Search,,,,,% Height+1
WinMove, Search,,,,,% Height
return
Open:
Run % duplicate["file" SubStr(A_GuiControl,5)]
return
OpenEarly:
Run % results["file" SubStr(A_GuiControl,5)]
return
WordSearch:
ExcelSearch:
PDFSearch:
PDFtoTextEXE:="C:\Users\" A_UserName "\Downloads\PDF..."
;RunWait,
return
GuiSize: ; Built-in GUI Event that is called when resizing the window
UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
return
#IfWinActive ahk_exe autohotkey.exe
~LButton::
MouseGetPos, Mx, My, A
WinGetPos,,,Wx, Wy, A
;Left = 8,351 to 24,367 (out of 733,376)
;Right = 692,351 to 707,367
;Down = 708,335 to 725, 350
;Up = 708,52 to 725, 67
If (Mx>8 && Mx<24 && My>Wy-26 && My<Wy-10) ; Left ; Need to recalibrate for any GUI
OnScroll(0,0,0x114,WinExist(),1)
If (Mx>Wx-41 && Mx<Wx-25 && My>Wy-26 && My<Wy-10) ; Right
OnScroll(1,0,0x114,WinExist(),1)
If (Mx>Wx-27 && Mx<Wx-4 && My>Wy-19 && My<Wy-4) ; Down
OnScroll(1,0,0x115,WinExist(),1)
If (Mx>Wx-27 && Mx<Wx-4 && My>27 && My<42) ; Up
OnScroll(0,0,0x115,WinExist(),1)
;Tooltip % (Mx>Wx-27) (Mx<Wx-4) (My>Wy-4) (My<Wy-19) "`n" My "`t" Wy "`t" Wy-4 "`t" Wy-19
return
#If
UpdateScrollBars(GuiNum, GuiWidth, GuiHeight)
{
static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1
Gui, %GuiNum%:Default
Gui, +LastFound
; Calculate scrolling area.
Left := Top := 9999
Right := Bottom := 0
WinGet, ControlList, ControlList
Loop, Parse, ControlList, `n
{
GuiControlGet, c, Pos, %A_LoopField%
if (cX < Left)
Left := cX
if (cY < Top)
Top := cY
if (cX + cW > Right)
Right := cX + cW
if (cY + cH > Bottom)
Bottom := cY + cH
}
Left -= 8
Top -= 8
Right += 8
Bottom += 8
ScrollWidth := Right-Left
ScrollHeight := Bottom-Top
; Initialize SCROLLINFO.
VarSetCapacity(si, 28, 0)
NumPut(28, si) ; cbSize
NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
; Update horizontal scroll bar.
; NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
;NumPut(ScrollWidth, si, 12) ; nMax
;NumPut(GuiWidth, si, 16) ; nPage
;DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1)
; Update vertical scroll bar.
NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
NumPut(ScrollHeight, si, 12) ; nMax
NumPut(GuiHeight, si, 16) ; nPage
DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &si, "int", 1)
if (Left < 0 && Right < GuiWidth)
x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left)
if (Top < 0 && Bottom < GuiHeight)
y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top)
if (x || y)
DllCall("ScrollWindow", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0)
}
OnScroll(wParam, lParam, msg, hwnd, trigger) ; I have added the trigger parameter
{
static SIF_ALL=0x17
SCROLL_STEP:=(trigger?100:10)
bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
VarSetCapacity(si, 28, 0)
NumPut(28, si) ; cbSize
NumPut(SIF_ALL, si, 4) ; fMask
if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
return
VarSetCapacity(rect, 16)
DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
new_pos := NumGet(si, 20, "int") ; nPos
action := wParam & 0xFFFF
if action = 0 ; SB_LINEUP
new_pos -= SCROLL_STEP
else if action = 1 ; SB_LINEDOWN
new_pos += SCROLL_STEP
else if action = 2 ; SB_PAGEUP
new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP
else if action = 3 ; SB_PAGEDOWN
new_pos += NumGet(rect, 12, "int") - SCROLL_STEP
else if (action = 5 || action = 4) ; SB_THUMBTRACK || SB_THUMBPOSITION
new_pos := wParam>>16
else if action = 6 ; SB_TOP
new_pos := NumGet(si, 8, "int") ; nMin
else if action = 7 ; SB_BOTTOM
new_pos := NumGet(si, 12, "int") ; nMax
else
return
min := NumGet(si, 8, "int") ; nMin
max := NumGet(si, 12, "int") - NumGet(si, 16, "int") ; nMax-nPage
new_pos := new_pos > max ? max : new_pos
new_pos := new_pos < min ? min : new_pos
old_pos := NumGet(si, 20, "int") ; nPos
x := y := 0
if bar = 0 ; SB_HORZ
x := old_pos-new_pos
else
y := old_pos-new_pos
; Scroll contents of window and invalidate uncovered area.
DllCall("ScrollWindow", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
; Update scroll bar.
NumPut(new_pos, si, 20, "int") ; nPos
DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
}
OnScrollBottom(wParam, lParam, msg, hwnd, trigger) ; I have added the trigger parameter
{
static SIF_ALL=0x17
SCROLL_STEP:=(trigger?100:10)
bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
VarSetCapacity(si, 28, 0)
NumPut(28, si) ; cbSize
NumPut(SIF_ALL, si, 4) ; fMask
if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
return
min := NumGet(si, 8, "int") ; nMin
max := NumGet(si, 12, "int") - NumGet(si, 16, "int") ; nMax-nPage
old_pos := NumGet(si, 20, "int") ; nPos
x := y := 0
if bar = 0 ; SB_HORZ
x := old_pos-max
else
y := old_pos-max
; Scroll contents of window and invalidate uncovered area.
DllCall("ScrollWindow", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
; Update scroll bar.
NumPut(max, si, 20, "int") ; nPos
DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
}
!5::
OnExit, please
MsgBox % FileExist(x:="Censored.pdf") ; used to make sure I had the path right
MsgBox % "|" A_LastError ; this message box appears
try ExtractText(result,x)
MsgBox % A_LastError ; this doesn't appear
return
please:
MsgBox % A_LastError
ExitApp
return
ExtractText(ByRef result, fileName) {
static hModule := DllCall("LoadLibrary", "Str", "C:\Users\" A_UserName "\Downloads\xd2tx215\dll\xd2txlib.dll\ExtractText", "Ptr")
fileLength := DllCall("C:\Users\" A_UserName "\Downloads\xd2tx215\dll\xd2txlib.dll\ExtractText", "Str", fileName, "Int", False, "Int*", fileText) ; this is what crashes things with that one file
result := StrGet( fileText, fileLength / 2 )
}