Can't call Everything_QueryW() twice

Discussion related to "Everything" 1.5 Alpha.
Post Reply
vefatica
Posts: 36
Joined: Sun Jun 11, 2023 6:27 pm

Can't call Everything_QueryW() twice

Post by vefatica »

As you may know from another forum/thread I have a plugin search tool (a command) for the TCC command interpreter (JPSoft). Relevant code (at the moment) looks like this.

Code: Select all

Everything_Reset();
	// process-wide; will allow me to be elevated when service client is unelevated
	Everything_SetSearch(psearch);
	Everything_SetMatchCase(match_case);
	Everything_SetRegex(regex);
	Everything_SetMatchPath(match_path);
	Everything_SetMatchWholeWord(match_whole_word);
	Everything_SetMax(sort ? EVERYTHING_MAX_RESULTS : num);
	//Printf(L"match_path = %d\r\n", Everything_GetMatchPath());
	if ( !Everything_QueryW(TRUE) )
	{
		Qprintf(STD_ERR, L"Everything_Query error: %lu\r\n", Everything_GetLastError());
		goto exit;
	}
	Beep(440,200);
	// output results here
	Everything_Reset();
	Everything_CleanUp();

	return rv;
It's dynamically linked to (some version of) Everything64.dll. The alpha 1.5 service and client are running.

When the DLL loaded is the one from the current SDK (2022-04-07, 94336 bytes) the ES command works only the first time; I hear the beep, see the output, and the shell returns to its prompt. The second time it fails; I don't hear the beep, there's no output (obviously) and the process is left using all of one processor and can't be interrupted.

When the DLL loaded is an older one (2017-03-22, 84,992 bytes) the ES command works any number of times.

The shell itself has some built-in Everything capabilities but it is not dynamically linked to an Everything DLL.
void
Developer
Posts: 16744
Joined: Fri Oct 16, 2009 11:31 pm

Re: Can't call Everything_QueryW() twice

Post by void »

Please try without the call to Everything_CleanUp.

There shouldn't be another call to the SDK after Everything_CleanUp.



Internally, Everything_CleanUp will call Everything_Reset and free any internal memory.
vefatica
Posts: 36
Joined: Sun Jun 11, 2023 6:27 pm

Re: Can't call Everything_QueryW() twice

Post by vefatica »

Yeah, I had found that out. Put the Cleanup before the Reset, it gets worse; remove it and its OK. That said, the code has had Cleanup after Reset (and before the next call to the plugin command) for years. The new DLL triggers the screw-up. Isn't that the sort of thing you'd like to avoid?

I suppose Cleanup would be appropriate in ShutdownPlugin(), called when my DLL is being unloaded (not necessarily at process termination).
void
Developer
Posts: 16744
Joined: Fri Oct 16, 2009 11:31 pm

Re: Can't call Everything_QueryW() twice

Post by void »

Everything_CleanUp should only be called once and before the dll is unloaded.

I've update the SDK so calling Everything_CleanUp will completely reset the default Everything state.
The next SDK call will succeed after Everything_CleanUp. (previously the next call would fail because the SDK state was undefined)

However, I still recommend only calling Everything_Reset and only calling Everything_CleanUp when you unload the DLL.

You don't have to call Everything_CleanUp.
However, there might be a few resources that are not freed to the system until your process ends.
vefatica
Posts: 36
Joined: Sun Jun 11, 2023 6:27 pm

Re: Can't call Everything_QueryW() twice

Post by vefatica »

The DLL isn't unloaded until I return from ShutdownPlugin. So that seems the perfect place for Cleanup.

I probably don't need to call Reset both before and after my command is used. Is there an advantage to one over the other?

Thanks!
void
Developer
Posts: 16744
Joined: Fri Oct 16, 2009 11:31 pm

Re: Can't call Everything_QueryW() twice

Post by void »

It doesn't hurt to call before.

I recommend calling Everything_Reset after Everything_QueryW(), after you have processed the results.

That way, any memory allocated for the results is returned to the system.
vefatica
Posts: 36
Joined: Sun Jun 11, 2023 6:27 pm

Re: Can't call Everything_QueryW() twice

Post by vefatica »

That's cool. Are tidbits like that documented anywhere?

Thanks!
vefatica
Posts: 36
Joined: Sun Jun 11, 2023 6:27 pm

Re: Can't call Everything_QueryW() twice

Post by vefatica »

Did you mean Everything_Query(FALSE)?
void
Developer
Posts: 16744
Joined: Fri Oct 16, 2009 11:31 pm

Re: Can't call Everything_QueryW() twice

Post by void »

If you call Everything_Query(FALSE), avoid calling Everything_Reset until after you receive the results.

Call Everything_Query(TRUE) if you want to block and wait for the results.

Then call Everything_Reset after you have processed the results.



Everything_CleanUp documentation does mention:

Everything_CleanUp should be the last call to the Everything SDK.
Post Reply