Everything_GetResultFileName doesn't work at .Net4.5 and later

Plug-in and third party software discussion.
Post Reply
kaifuzi
Posts: 19
Joined: Thu May 30, 2019 12:53 am

Everything_GetResultFileName doesn't work at .Net4.5 and later

Post by kaifuzi »

I found that Everything_GetResultFileName doesn't work at .Net4.5 and later version, it will cause application crash, but it works at .Net4 and before.
Does any one meet this problem?
void
Developer
Posts: 15096
Joined: Fri Oct 16, 2009 11:31 pm

Re: Everything_GetResultFileName doesn't work at .Net4.5 and later

Post by void »

What language?

If you are using C#, could you please try changing your declaration of Everything_GetResultFileNameW to:

Code: Select all

[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
public static extern IntPtr Everything_GetResultFileNameW(int nIndex);
I've heard reports of the old string declaration crashing:
public static extern string Everything_GetResultFileName(UInt32 nIndex);

Please try using Marshal.PtrToStringUni to convert the IntPtr to a string.
kaifuzi
Posts: 19
Joined: Thu May 30, 2019 12:53 am

Re: Everything_GetResultFileName doesn't work at .Net4.5 and later

Post by kaifuzi »

This crash problem is in C# and VB.net, .Net4.5 and after.
I changed the declare as you suggest In C#, it works!

But I still get a problem in VB.net.
I use below code, it works:

Code: Select all

Public Declare Function Everything_GetResultFileNameA Lib "Everything32.dll" (ByVal index As Integer) As IntPtr
Dim name As String = Marshal.PtrToStringAnsi(Everything_GetResultFileNameA(CInt(i)))
In below code, I can't get the file name:

Code: Select all

    Public Declare Function Everything_GetResultFileNameW Lib "Everything32.dll" (ByVal index As Integer) As IntPtr
    '<DllImport("Everything32.dll", CharSet:=CharSet.Unicode)>
    'Public Shared Function Everything_GetResultFileNameW(ByVal nIndex As Integer) As IntPtr
    'End Function
    Dim name As String = Marshal.PtrToStringUni(Everything_GetResultFileNameW(CInt(i)))
Could you please let me know how to use Everything_GetResultFileNameW in VB.net?
Thanks!
void
Developer
Posts: 15096
Joined: Fri Oct 16, 2009 11:31 pm

Re: Everything_GetResultFileName doesn't work at .Net4.5 and later

Post by void »

Are you calling Everything_QueryA or Everything_QueryW?

The ansi/wchar calls to Everything_Query must match Everything_GetResultFileName, eg:
To call Everything_GetResultFileNameW you must call Everything_QueryW (not Everything_QueryA).

Please try the following:

Code: Select all

' Add an Imports statement at the top of the class, structure, or
' module that uses the DllImport attribute.

Public Class Form1

    Public Declare Unicode Function Everything_SetSearchW Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal search As String) As UInt32
    Public Declare Unicode Function Everything_SetRequestFlags Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal dwRequestFlags As UInt32) As UInt32
    Public Declare Unicode Function Everything_QueryW Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal bWait As Integer) As Integer
    Public Declare Unicode Function Everything_GetNumResults Lib "d:\dev\everything\sdk\dll\Everything32.dll" () As UInt32
    Public Declare Unicode Function Everything_GetResultFileNameW Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal index As UInt32) As IntPtr
    Public Declare Unicode Function Everything_GetLastError Lib "d:\dev\everything\sdk\dll\Everything32.dll" () As UInt32
    Public Declare Unicode Function Everything_GetResultFullPathNameW Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal index As UInt32, ByVal buf As System.Text.StringBuilder, ByVal size As UInt32) As UInt32
    Public Declare Unicode Function Everything_GetResultSize Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal index As UInt32, ByRef size As UInt64) As Integer
    Public Declare Unicode Function Everything_GetResultDateModified Lib "d:\dev\everything\sdk\dll\Everything32.dll" (ByVal index As UInt32, ByRef ft As UInt64) As Integer

    Public Const EVERYTHING_REQUEST_FILE_NAME = &H1
    Public Const EVERYTHING_REQUEST_PATH                                 = &H00000002
    Public Const EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME              = &H00000004
    Public Const EVERYTHING_REQUEST_EXTENSION                            = &H00000008
    Public Const EVERYTHING_REQUEST_SIZE                                 = &H00000010
    Public Const EVERYTHING_REQUEST_DATE_CREATED                         = &H00000020
    Public Const EVERYTHING_REQUEST_DATE_MODIFIED                        = &H00000040
    Public Const EVERYTHING_REQUEST_DATE_ACCESSED                        = &H00000080
    Public Const EVERYTHING_REQUEST_ATTRIBUTES                           = &H00000100
    Public Const EVERYTHING_REQUEST_FILE_LIST_FILE_NAME                  = &H00000200
    Public Const EVERYTHING_REQUEST_RUN_COUNT                            = &H00000400
    Public Const EVERYTHING_REQUEST_DATE_RUN                             = &H00000800
    Public Const EVERYTHING_REQUEST_DATE_RECENTLY_CHANGED                = &H00001000
    Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FILE_NAME                = &H00002000
    Public Const EVERYTHING_REQUEST_HIGHLIGHTED_PATH                     = &H00004000
    Public Const EVERYTHING_REQUEST_HIGHLIGHTED_FULL_PATH_AND_FILE_NAME  = &H00008000

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Everything_SetSearchW(TextBox1.Text)
        Everything_SetRequestFlags(EVERYTHING_REQUEST_FILE_NAME Or EVERYTHING_REQUEST_PATH Or EVERYTHING_REQUEST_SIZE Or EVERYTHING_REQUEST_DATE_MODIFIED)
        Everything_QueryW(1)

        Dim NumResults As UInt32
        Dim i As UInt32
        Dim filename As New System.Text.StringBuilder(260)
        Dim size As UInt64
        Dim ftdm As UInt64
        Dim DateModified As System.DateTime

        NumResults = Everything_GetNumResults()

        ListBox1.Items.Clear()

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

                Everything_GetResultFullPathNameW(i, filename, filename.Capacity)
                Everything_GetResultSize(i, size)
                Everything_GetResultDateModified(i, ftdm)

                DateModified = System.DateTime.FromFileTime(ftdm)

                '                ListBox1.Items.Insert(i, filename.ToString() & " size:" & size & " date:" & DateModified.ToString())
                ListBox1.Items.Insert(i, System.Runtime.InteropServices.Marshal.PtrToStringUni(Everything_GetResultFileNameW(i)) & " Size:" & size & " Date Modified:" & DateModified.ToString())

            Next
        End If

    End Sub

End Class

kaifuzi
Posts: 19
Joined: Thu May 30, 2019 12:53 am

Re: Everything_GetResultFileName doesn't work at .Net4.5 and later

Post by kaifuzi »

Yes, it works after I call Everything_QueryW. My mistake.
Thanks a lot!
Post Reply