Created
November 24, 2022 18:38
-
-
Save jpluimers/1a0d9d5feca2a95fbe320c7290c6cd2b to your computer and use it in GitHub Desktop.
IPC C Example; A C example to send a search query to Everything using WM_COPYDATA and retrieve the results. Note: requires Everything running in the background.; https://www.voidtools.com/support/everything/sdk/ipc_c_example/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define COPYDATA_QUERYCOMPLETE 0 | |
BOOL sendquery(HWND hwnd,DWORD max_results,WCHAR *search_string,BOOL regex,BOOL match_case,BOOL match_whole_word,BOOL match_path) | |
{ | |
EVERYTHING_IPC_QUERY *query; | |
DWORD len; | |
DWORD size; | |
HWND everything_hwnd; | |
COPYDATASTRUCT cds; | |
everything_hwnd = FindWindow(EVERYTHING_IPC_WNDCLASS,0); | |
if (everything_hwnd) | |
{ | |
len = (int)wcslen(search_string); | |
size = sizeof(EVERYTHING_IPC_QUERY) - sizeof(WCHAR) + len*sizeof(WCHAR) + sizeof(WCHAR); | |
query = (EVERYTHING_IPC_QUERY *)HeapAlloc(GetProcessHeap(),0,size); | |
if (query) | |
{ | |
query->max_results = max_results; | |
query->offset = 0; | |
query->reply_copydata_message = COPYDATA_QUERYCOMPLETE; | |
query->search_flags = (regex?EVERYTHING_IPC_REGEX:0) | (match_case?EVERYTHING_IPC_MATCHCASE:0) | (match_whole_word?EVERYTHING_IPC_MATCHWHOLEWORD:0) | (match_path?EVERYTHING_IPC_MATCHPATH:0); | |
query->reply_hwnd = hwnd; | |
CopyMemory(query->search_string,search_string,(len+1)*sizeof(WCHAR)); | |
cds.cbData = size; | |
cds.dwData = EVERYTHING_IPC_COPYDATAQUERY; | |
cds.lpData = query; | |
if (SendMessage(everything_hwnd,WM_COPYDATA,(WPARAM)hwnd,(LPARAM)&cds) == TRUE) | |
{ | |
HeapFree(GetProcessHeap(),0,query); | |
return TRUE; | |
} | |
else | |
{ | |
// Everything IPC service not running | |
} | |
HeapFree(GetProcessHeap(),0,query); | |
} | |
} | |
else | |
{ | |
// the everything window was not found. | |
// we can optionally RegisterWindowMessage("EVERYTHING_IPC_CREATED") and | |
// wait for Everything to post this message to all top level windows when its up and running. | |
} | |
return FALSE; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void DisplayPathName(TCHAR *path,TCHAR *filename) | |
{ | |
// ... | |
// do something with path and filename | |
// ... | |
} | |
LRESULT CALLBACK window_proc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam) | |
{ | |
DWORD i; | |
EVERYTHING_IPC_LIST *list | |
switch(uMsg) | |
{ | |
case WM_COPYDATA: | |
{ | |
COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lParam; | |
switch(cds->dwData) | |
{ | |
case COPYDATA_QUERYCOMPLETE: | |
list = (EVERYTHING_IPC_LIST *)cds->lpData; | |
for(i=0;i<list->numitems;i++) | |
{ | |
DisplayPathName(EVERYTHING_IPC_ITEMPATH(list,&list->items[i]),EVERYTHING_IPC_ITEMFILENAME(list,&list->items[i])) | |
} | |
return TRUE; | |
} | |
break; | |
} | |
} | |
return DefWindowProc(hwnd,msg,wParam,lParam); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment