Example-Extension/ExampleExtension/Extension.cpp
2018-09-22 17:33:40 -04:00

50 lines
3.1 KiB
C++
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "Extension.h"
BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
MessageBoxW(NULL, L"Extension Loaded", L"", MB_OK);
break;
case DLL_PROCESS_DETACH:
MessageBoxW(NULL, L"Extension Removed", L"", MB_OK);
break;
}
return TRUE;
}
//#define COPY_CLIPBOARD
//#define EXTRA_NEWLINES
/**
* Param sentence: sentence received by NextHooker (UTF-16).
* Param sentenceInfo: contains miscellaneous info about the sentence. See README.md
* Return value: whether the sentence was modified.
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it.
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
*/
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{
#ifdef COPY_CLIPBOARD
// This example extension automatically copies sentences from the hook currently selected by the user into the clipboard.
if (sentenceInfo["current select"] == 1)
{
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (sentence.size() + 2) * sizeof(wchar_t));
memcpy(GlobalLock(hMem), sentence.c_str(), (sentence.size() + 2) * sizeof(wchar_t));
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
}
return false;
#endif // COPY_CLIPBOARD
#ifdef EXTRA_NEWLINES
// This example extension adds extra newlines to all sentences.
sentence += L"\r\n";
return true;
#endif // EXTRA_NEWLINES
}