Example-Extension/ExampleExtension/Extension.cpp

27 lines
2.1 KiB
C++
Raw Normal View History

2018-07-12 08:07:22 +08:00
<EFBFBD><EFBFBD>#include "stdafx.h"
extern "C"
{
/**
* Param sentence: wstring of the sentence received by NextHooker
2018-07-27 13:59:54 +08:00
* Param info: map containing additional info about the sentence
2018-07-29 03:41:47 +08:00
* You can modify the params, and future extensions will receive them
* NextHooker will display the sentence after all extensions have had a chance to process and/or modify it
2018-07-12 08:07:22 +08:00
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
*/
2018-07-29 03:41:47 +08:00
void __declspec(dllexport) OnNewSentence(std::wstring& sentence, std::unordered_map<std::string, int>& info)
2018-07-12 08:07:22 +08:00
{
2018-07-12 08:17:18 +08:00
// This example extension does nothing except place sentences from the hook currently selected by the user into the clipboard
2018-07-27 13:59:54 +08:00
if (info["current select"])
2018-07-12 08:17:18 +08:00
{
2018-07-14 01:26:47 +08:00
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (sentence.size() + 1) * sizeof(wchar_t));
memcpy(GlobalLock(hMem), sentence.c_str(), (sentence.size() + 1) * sizeof(wchar_t));
2018-07-12 08:17:18 +08:00
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
}
2018-07-12 08:07:22 +08:00
}
}