Using Visual Basic SDK with Named Instances

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
DanoLeMano
Posts: 8
Joined: Sat Jul 17, 2021 10:30 pm

Using Visual Basic SDK with Named Instances

Post by DanoLeMano »

I am currently using some Visual Basic code based on the example provided in the SDK.

https://www.voidtools.com/support/every ... ual_basic/

Here is a section of my code which works perfectly for the unnamed instance of Everything, but for some reason it does not work when I use a Named Instance. Is there something about Named Instances that might cause this VB code to not function properly?

Code: Select all

Module Program
    Public Declare Function Everything_SetSearchA Lib "C:\Everything\Everything32.dll" (ByVal search As String) As UInt32
    Public Declare Function Everything_SetRequestFlags Lib "C:\Everything\Everything32.dll" (ByVal dwRequestFlags As UInt32) As UInt32
    Public Declare Function Everything_QueryA Lib "C:\Everything\Everything32.dll" (ByVal bWait As Integer) As Integer
    Public Declare Function Everything_GetNumResults Lib "C:\Everything\Everything32.dll" () As UInt32
    Public Declare Function Everything_GetResultFileNameA Lib "C:\Everything\Everything32.dll" (ByVal index As UInt32) As String
    Public Declare Function Everything_GetLastError Lib "C:\Everything\Everything32.dll" () As UInt32
    Public Declare Function Everything_GetResultFullPathNameA Lib "C:\Everything\Everything32.dll" (ByVal index As UInt32, ByVal buf As System.Text.StringBuilder, ByVal size As UInt32) As UInt32
    Public Declare Function Everything_GetResultSize Lib "C:\Everything\Everything32.dll" (ByVal index As UInt32, ByRef size As UInt64) As Integer
    Public Declare Function Everything_GetResultDateModified Lib "C:\Everything\Everything32.dll" (ByVal index As UInt32, ByRef ft As UInt64) As Integer

    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 Sub Main(args() As String)

        If (UBound(args)) <> 1 Then
            Console.WriteLine("Arguments Expected-2. First is Search String. Second is Complete File Path.")
            Exit Sub
        End If

        Dim DirectoryPath As String
        DirectoryPath = System.IO.Path.GetDirectoryName(args(1))
        'Console.WriteLine(DirectoryPath)
        If Not (System.IO.Directory.Exists(DirectoryPath)) Then
            Console.WriteLine("Folder/Directory Path Does Not Exits")
            Exit Sub
        End If

        Everything_SetSearchA(args(0))
        Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME Or EVERYTHING_REQUEST_EXTENSION Or EVERYTHING_REQUEST_PATH Or EVERYTHING_REQUEST_SIZE Or EVERYTHING_REQUEST_DATE_MODIFIED)
        Everything_QueryA(1)

        Dim NumResults As UInt32
        Dim i As UInt32
        Dim FullFileFolderPath As New System.Text.StringBuilder(260)
        Dim size As UInt64
        Dim ftdm As UInt64
        Dim DateModified As System.DateTime
        Dim strFileExtension As String, DotPosition As Integer

        Dim Output As String

        Output = ""
        NumResults = Everything_GetNumResults()

        If NumResults > 0 Then
            For i = 0 To NumResults - 1

                Everything_GetResultFullPathNameA(i, FullFileFolderPath, FullFileFolderPath.Capacity)

                strFileExtension = Everything_GetResultFileNameA(i)
                DotPosition = strFileExtension.LastIndexOf(".")
                If (DotPosition <> -1) Then
                    strFileExtension = strFileExtension.Substring(DotPosition, strFileExtension.Length - DotPosition)
                Else
                    strFileExtension = ""
                End If
                Everything_GetResultSize(i, size)
                Everything_GetResultDateModified(i, ftdm)

                DateModified = System.DateTime.FromFileTime(ftdm)

                Output = Output & FullFileFolderPath.ToString() & "|" & size & "|" & DateModified.ToString() & "|" & strFileExtension & vbCr
            Next
            Output = Output.Substring(0, Output.Length - 1)
            My.Computer.FileSystem.WriteAllText(args(1), Output, False)

        End If

    End Sub


End Module
void
Developer
Posts: 16748
Joined: Fri Oct 16, 2009 11:31 pm

Re: Using Visual Basic SDK with Named Instances

Post by void »

The SDK does not support named instances.

It is possible to recompile the SDK to use your named instance.
Replace EVERYTHING_IPC_WNDCLASS or "EVERYTHING_TASKBAR_NOTIFICATION" with:
"EVERYTHING_TASKBAR_NOTIFICATION (instance-name)"

I plan to add support for named instances in the next major SDK update.
DanoLeMano
Posts: 8
Joined: Sat Jul 17, 2021 10:30 pm

Re: Using Visual Basic SDK with Named Instances

Post by DanoLeMano »

I wish I knew how to do this. Are there instructions anywhere for how to recompile the SDK?
void
Developer
Posts: 16748
Joined: Fri Oct 16, 2009 11:31 pm

Re: Using Visual Basic SDK with Named Instances

Post by void »

Basic instructions:
  • Download Microsoft Visual Studio
  • Open vs\sdk.dll.vcproj
  • Convert the project if needed.
  • In Everything.c, change the following line:
    everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0);
    to:
    everything_hwnd = FindWindow(L"EVERYTHING_TASKBAR_NOTIFICATION (instance-name)",0);
  • Build the project.
-or-

Send your instance-name to support@voidtools.com and I'll compile a new dll for you.
DanoLeMano
Posts: 8
Joined: Sat Jul 17, 2021 10:30 pm

Re: Using Visual Basic SDK with Named Instances

Post by DanoLeMano »

Thank you for the detailed instructions on how to compile a new DLL from the SDK.

More importantly, I discovered that the Command Line Interface program (es.exe) supports both named instances and exporting to csv. Since I am able to do everything I need to using the CLI, I have no need to develop further with the SDK.
Post Reply