Thanks. Confirmed. Your code works like a charm with Excel 2019 x64, as well.
Back to my test sub, after "compressing" my code a bit, I could not reproduce the crashes, that I had before.
But, there is still something weird going on, now, when I am modifying the VBA source code for Everything DLL declarations. The compiler throws "insufficient memory", as soon as I copy & paste a declaration statement from here to there. Comment after paste helps. But ?!?!
Ok. That's VBA. I have to drill further. With Everything, everything is fine
This is my latest running version.
Code: Select all
' everythingTest
Option Explicit
Declare PtrSafe Function Everything_GetNumResults Lib "d:\dropbox\autover\vba\everything\everything64.dll" () As Long
Declare PtrSafe Function Everything_GetResultFullPathNameW Lib "d:\dropbox\autover\vba\everything\everything64.dll" _
(ByVal index As Long, ByVal ins As LongPtr, ByVal size As Long) As Long
Declare PtrSafe Function Everything_GetResultPathW Lib "d:\dropbox\autover\vba\everything\everything64.dll" _
(ByVal index As Long) As LongPtr ' LPCWSTR
Declare PtrSafe Function Everything_GetResultFileNameW Lib "d:\dropbox\autover\vba\everything\everything64.dll" _
(ByVal index As Long) As LongPtr ' LPCWSTR
Private Declare PtrSafe Function lstrlenW Lib "kernel32.dll" (ByVal lpString As LongPtr) As Long
Private Declare PtrSafe Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
(ByVal Destination As LongPtr, ByVal Source As LongPtr, ByVal Length As Long)
' https://codekabinett.com/rdumps.php?Lang=2&targetDoc=api-pointer-convert-vba-string-ansi-unicode
Public Function StringFromPointerW(ByVal pointerToString As LongPtr) As String
Const BYTES_PER_CHAR As Integer = 2
Dim tmpBuffer() As Byte
Dim byteCount As Long
byteCount = lstrlenW(pointerToString) * BYTES_PER_CHAR
If byteCount > 0 Then
ReDim tmpBuffer(0 To byteCount - 1) As Byte
Call CopyMemory(VarPtr(tmpBuffer(0)), pointerToString, byteCount)
End If
StringFromPointerW = tmpBuffer
End Function ' StringFromPointerW()
Sub testEverything()
Dim search As String
search = "d: ""so important"""
Everything_SetSearchW StrPtr(search)
Everything_QueryW True
Dim n As Long
n = Everything_GetNumResults
If n > 0 Then
Const MAXPATHLEN = 260 ' 255 Char + 4 Length + Null
Dim maxPath As String
maxPath = String(MAXPATHLEN, 0)
ReDim a(n, 2) As String
a(0, 0) = "fullPath"
a(0, 1) = "path"
a(0, 2) = "filename"
Dim i As Long
For i = 1 To n
a(i, 0) = Left(maxPath, Everything_GetResultFullPathNameW(i - 1, StrPtr(maxPath), 260))
a(i, 1) = StringFromPointerW(Everything_GetResultPathW(i - 1))
a(i, 2) = StringFromPointerW(Everything_GetResultFileNameW(i - 1))
next i
End If
With Sheets(1)
.Range("a1").CurrentRegion.Clear
.Range("a1").Resize(i, 3) = a
.Range("a1:c1").Font.Bold = True
.Columns("a:c").AutoFit
End With
End Sub ' testEverything