Create new process and query. Cannot get result.

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
yemanqitipo
Posts: 11
Joined: Sat Dec 17, 2022 9:02 am

Create new process and query. Cannot get result.

Post by yemanqitipo »

Hello, I hava a problem when calling everything sdk.
Assuming there are no everything.exe processes on the machine now. So I create a new everything.exe process with CreateProcessA api.
Then I call Everything_SetSearchW、Everything_QueryW、Everything_GetResultFullPathNameW in sequence.
But I Can't get result of searching.

The detailed code is as follows:

Code: Select all

#include <iostream>
#include "Everything.h"

#pragma comment(lib, "Everything64.lib")

bool CreateProcessWithStr(char* commandLine) {
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	ZeroMemory(&pi, sizeof(pi));

	if (!CreateProcessA(NULL, commandLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
		return false;
	}
	//Sleep(5000);
	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);

	return true;
}

bool search(LPCWSTR searchString) {
	CreateProcessWithStr("Everything.exe -startup");

	DWORD i;
	Everything_SetSearchW(searchString);
	Everything_QueryW(true);
	for (i = 0; i < Everything_GetNumResults(); i++)
	{
		wchar_t buf[MAX_PATH];
		Everything_GetResultFullPathNameW(i, buf, sizeof(buf) / sizeof(TCHAR));
		MessageBoxW(0, buf, 0, MB_OK);
	}

	CreateProcessWithStr("Everything.exe -quit");
	return 0;
}

int main() {
	search(L"aabbcc");
	return 0;
}
Please note: If I uncomment the code Sleep(5000) . It works as expected。
I guess that after the moment Calling CreateProcessA, everything process need some time to initialize。Then it will get ready.
Am I right?
I donot Wanna the Sleep(5000) .。 Is there an alternative?
void
Developer
Posts: 16773
Joined: Fri Oct 16, 2009 11:31 pm

Re: Create new process and query. Cannot get result.

Post by void »

Please try polling Everything_IsDBLoaded

Wait until this function returns TRUE after starting the process.

Consider setting a timeout after 1 minute to fail.
Post Reply