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;
}
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?