SDK encoder bug

Plug-in and third party software discussion.
Post Reply
ssyfzy
Posts: 3
Joined: Fri Jul 12, 2024 7:56 pm

SDK encoder bug

Post by ssyfzy »

My language of windows is Chinese, I can use Korean `리마스터` to search file in Everything.exe
pic.png
pic.png (14.43 KiB) Viewed 10502 times
But when I use the same keyword to search by the following code, I'll get lots of results which don't match my keyword, seems the SDK has bug, I think it always use default encoder of windows, and `리마스터` can't encode correctly, so it encoded as `????`, those lots of result are macthed to keyword `????`

```C#
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

class Program
{
static void Main()
{
var files = FindFiles("리마스터"); // Chinese/English word work fine
var files2 = FindFiles("????");
Console.WriteLine(files.SetEquals(files2));
Console.ReadKey();
}

[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
public static extern void Everything_GetResultFullPathNameW(int nIndex, StringBuilder lpString, int nMaxCount);

[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
public static extern void Everything_SetSearch(string lpSearchString);

[DllImport("Everything64.dll")]
public static extern void Everything_Query(bool bWait);

[DllImport("Everything64.dll")]
public static extern int Everything_GetNumResults();

public static HashSet<string> FindFiles(string fileName)
{
var list = new HashSet<string>();
Everything_SetSearch(fileName);
Everything_Query(true);
int count = Everything_GetNumResults();
for (int i = 0; i < count; i++)
{
StringBuilder sb = new StringBuilder(1000);
Everything_GetResultFullPathNameW(i, sb, sb.Capacity);
list.Add(sb.ToString());
}
return list;
}
}
```
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: SDK encoder bug

Post by void »

The C# example works when searching for 리마스터

If you are manually typing 리마스터 in your code, please make sure the c# file has unicode support.
You can change this in Visual Studio under File -> Advanced Save Options. (save the file as UTF-8 or other Unicode supported encoding)
ssyfzy
Posts: 3
Joined: Fri Jul 12, 2024 7:56 pm

Re: SDK encoder bug

Post by ssyfzy »

No, I think it work only when the windows language is Korean also.

There's one more test:
pic2.png
pic2.png (15.92 KiB) Viewed 10483 times

This time I use English keyword `mytest123.txt`, and it work fine in Everything.exe, but when I search this keyword by SDK, I get `????` rather than original Koeran string also:
pic3.png
pic3.png (44.03 KiB) Viewed 10483 times
My version is Everything-1.4.1.1024.x64, and SDK dll modified time is 2023/06/13
Last edited by ssyfzy on Fri Jul 12, 2024 11:40 pm, edited 2 times in total.
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: SDK encoder bug

Post by void »

Please change the declaration of Everything_SetSearch to:

[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
public static extern void Everything_SetSearchW(string lpSearchString);



Please change the declaration of Everything_QueryW to:

[DllImport("Everything64.dll")]
public static extern bool Everything_QueryW(bool bWait);
ssyfzy
Posts: 3
Joined: Fri Jul 12, 2024 7:56 pm

Re: SDK encoder bug

Post by ssyfzy »

Useless.
I already tested that before I posted this topic.

Maybe you do something in SDK like this:
pic4.png
pic4.png (50.63 KiB) Viewed 10473 times
Default encoder can't encode Korean correctly, maybe you should always use Unicode/UTF8 in SDK dll
Last edited by ssyfzy on Fri Jul 12, 2024 11:56 pm, edited 1 time in total.
void
Developer
Posts: 16770
Joined: Fri Oct 16, 2009 11:31 pm

Re: SDK encoder bug

Post by void »

The SDK supports Unicode.

This is an encoding issue with your C# file.
ssyfzy
Posts: 3
Joined: Fri Jul 12, 2024 7:56 pm

Re: SDK encoder bug

Post by ssyfzy »

[DllImport("Everything64.dll", CharSet = CharSet.Unicode)]
public static extern void Everything_Query(bool bWait);

Everything_Query should also use unicode version.

This function doesn't take any string parameter, that's why I thought it's unnecessary to set CharSet. I haven't seen any other API without string parameter need CharSet in the past.

Fixed, thanks!
Post Reply