Use of Everything from Excel VBA

Plug-in and third party software discussion.
Post Reply
urijoh
Posts: 4
Joined: Fri Jun 19, 2020 11:53 am

Use of Everything from Excel VBA

Post by urijoh » Fri Jun 19, 2020 12:38 pm

Hej there,

I am not really a programmer, but at least a passionate user of VBA in Excel and Solidworks. I'd love to integrate everything in some of my VBA code, but failed so far:
- register the everything64.dll with regsvr32 does return an error
- set a reference in VBA does not work
- using the declare function does not work
Has anybody ever used the Everything SDK using VBA?
Does somebody have an example (I could not make the VB sample working on VBA)?

NotNull
Posts: 2385
Joined: Wed May 24, 2017 9:22 pm

Re: Use of Everything from Excel VBA

Post by NotNull » Fri Jun 19, 2020 1:13 pm

urijoh wrote:
Fri Jun 19, 2020 12:38 pm
- register the everything64.dll with regsvr32 does return an error
everything64.dll does not need registration.
(can't help yiu with your other questions)

void
Site Admin
Posts: 5799
Joined: Fri Oct 16, 2009 11:31 pm

Re: Use of Everything from Excel VBA

Post by void » Mon Jun 22, 2020 1:32 am

I only have the Visual Basic SDK example.
https://www.voidtools.com/Everything.SDK.Visual.Basic.Example.zip
I could not make the VB sample working on VBA
What happens?
Hope I can help..

urijoh
Posts: 4
Joined: Fri Jun 19, 2020 11:53 am

Re: Use of Everything from Excel VBA

Post by urijoh » Mon Jun 22, 2020 5:29 am

Trials_Everything.zip
(22 Bytes) Downloaded 73 times
to me, it seems that it does nothing?!?
Find attached the Excel-File I used for my trials. I had to change some stuff in order to make it run in VBA (see header in this VBA module). It seems now to run, but it does always return a "0" on the GetNumResults request.

Would be really cool if you could find the solution for this :D

void
Site Admin
Posts: 5799
Joined: Fri Oct 16, 2009 11:31 pm

Re: Use of Everything from Excel VBA

Post by void » Mon Jun 22, 2020 5:35 am

The SDK requires Everything is running in the background.

Is Everything running in the background?

Trials_Everything.zip looks empty?

urijoh
Posts: 4
Joined: Fri Jun 19, 2020 11:53 am

Re: Use of Everything from Excel VBA

Post by urijoh » Mon Jun 22, 2020 6:14 am

Trials_Everything.zip
(16.19 KiB) Downloaded 84 times
Sorry for the missing content in the .zip - it should now contain the Excel file with the VBA Macro.
Everything is running in the background (always all day long...)

void
Site Admin
Posts: 5799
Joined: Fri Oct 16, 2009 11:31 pm

Re: Use of Everything from Excel VBA

Post by void » Mon Jun 22, 2020 9:06 am

Thanks for the Trials VBA.

I've made the following changes:

Code: Select all

'Note: sample copied from https://www.voidtools.com/support/everything/sdk/visual_basic/
'Replaced for VBA usage
' - UINT32 with LONG
' - UINT64 with LONGLONG
' - INTPtr with LONGPtr
' - System.Text.StringBuilder with String
' - System.DateTime with String
' - filename.Capacity with filesize

Public Declare PtrSafe Function Everything_SetSearchW Lib "C:\SDK\Everything64.dll" (ByVal ins As LongPtr) As Long
Public Declare PtrSafe Function Everything_SetRequestFlags Lib "C:\SDK\Everything64.dll" (ByVal dwRequestFlags As Long) As Long
Public Declare PtrSafe Function Everything_QueryW Lib "C:\SDK\Everything64.dll" (ByVal bWait As Integer) As Integer
Public Declare PtrSafe Function Everything_GetNumResults Lib "C:\SDK\Everything64.dll" () As Long
Public Declare PtrSafe Function Everything_GetResultFileNameW Lib "C:\SDK\Everything64.dll" (ByVal index As Long) As LongPtr
Public Declare PtrSafe Function Everything_GetLastError Lib "C:\SDK\Everything64.dll" () As Long
Public Declare PtrSafe Function Everything_GetResultFullPathNameW Lib "C:\SDK\Everything64.dll" (ByVal index As Long, ByVal ins As LongPtr, ByVal size As Long) As Long
Public Declare PtrSafe Function Everything_GetResultSize Lib "C:\SDK\Everything64.dll" (ByVal index As Long, ByRef size As LongLong) As Integer         'size UInt64
Public Declare PtrSafe Function Everything_GetResultDateModified Lib "C:\SDK\Everything64.dll" (ByVal index As Long, ByRef ft As LongLong) As Integer   'ft UInt64

Public Const EVERYTHING_REQUEST_FILE_NAME = &H1
Public Const EVERYTHING_REQUEST_PATH = &H2
Public Const EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME = &H4
Public Const EVERYTHING_REQUEST_EXTENSION = &H8
Public Const EVERYTHING_REQUEST_SIZE = &H10
Public Const EVERYTHING_REQUEST_DATE_CREATED = &H20
Public Const EVERYTHING_REQUEST_DATE_MODIFIED = &H40
Public Const EVERYTHING_REQUEST_DATE_ACCESSED = &H80
Public Const EVERYTHING_REQUEST_ATTRIBUTES = &H100
Public Const EVERYTHING_REQUEST_FILE_LIST_FILE_NAME = &H200
Public Const EVERYTHING_REQUEST_RUN_COUNT = &H400
Public Const EVERYTHING_REQUEST_DATE_RUN = &H800
Public Const EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED = &H1000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME = &H2000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_PATH = &H4000
Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = &H8000

Public Type FILETIME
    dwLowDateTime As Long
    dwHighDateTime As Long
End Type

Public Type SYSTEMTIME
    wYear As Integer
    wMonth As Integer
    wDayOfWeek As Integer
    wDay As Integer
    wHour As Integer
    wMinute As Integer
    wSecond As Integer
    wMilliseconds As Integer
End Type

Private Declare PtrSafe Function FileTimeToSystemTime Lib "kernel32" (ByRef ft As LongLong, lpSystemTime As SYSTEMTIME) As Long
Private Declare PtrSafe Function SystemTimeToTzSpecificLocalTime Lib "kernel32" (ByVal tzi As LongPtr, lpst As SYSTEMTIME, lplt As SYSTEMTIME) As Long
Private Declare PtrSafe Function SystemTimeToVariantTime Lib "OLEAUT32.DLL" (lpSystemTime As SYSTEMTIME, vtime As Date) As Long

Sub SimpleTest()
    Dim EyText As String
    Dim test As Boolean
    EyText = "Everything"
    Everything_SetSearchW (StrPtr(EyText))
    Everything_SetRequestFlags (EVERYTHING_REQUEST_FILE_NAME Or EVERYTHING_REQUEST_PATH Or EVERYTHING_REQUEST_SIZE Or EVERYTHING_REQUEST_DATE_MODIFIED)
    test = Everything_QueryW(True)
    Debug.Print test

    Dim NumResults As Long
    Dim i As Long
    Dim filename As String
    Dim filesize As Long
    Dim size As LongLong
    Dim ftdm As LongLong
    Dim stdm As SYSTEMTIME
    Dim ltdm As SYSTEMTIME
    Dim DateModified As Date

    filename = String(260, 0)

    NumResults = Everything_GetNumResults()
    Debug.Print NumResults

    If NumResults > 0 Then
        For i = 0 To NumResults - 1
            test = Everything_GetResultFullPathNameW(i, StrPtr(filename), 260)
            Debug.Print filename
            
            test = Everything_GetResultSize(i, size)
            Debug.Print size
            
            test = Everything_GetResultDateModified(i, ftdm)
            test = FileTimeToSystemTime(ftdm, stdm)
            test = SystemTimeToTzSpecificLocalTime(0, stdm, ltdm)
            test = SystemTimeToVariantTime(ltdm, DateModified)
            Debug.Print DateModified
        Next
    End If
End Sub

Notes:

Use LongPtr for strings.

urijoh
Posts: 4
Joined: Fri Jun 19, 2020 11:53 am

Re: Use of Everything from Excel VBA

Post by urijoh » Mon Jun 22, 2020 9:37 am

WOW, it does work, You are the best!!!

Post Reply