Local-MT-Extension/ExampleExtension/Extension.cpp

57 lines
4.7 KiB
C++
Raw Normal View History

2018-07-30 05:35:40 +08:00
<EFBFBD><EFBFBD>#include "stdafx.h"
struct InfoForExtension
{
const char* propertyName;
int propertyValue;
InfoForExtension* nextProperty;
};
2018-07-30 14:56:45 +08:00
// Traverses linked list to find info.
2018-07-30 05:35:40 +08:00
int GetProperty(const char* propertyName, InfoForExtension* miscInfo)
{
InfoForExtension* miscInfoTraverser = miscInfo;
while (miscInfoTraverser != nullptr)
if (strcmp(propertyName, miscInfoTraverser->propertyName) == 0) return miscInfoTraverser->propertyValue;
else miscInfoTraverser = miscInfoTraverser->nextProperty;
return 0;
}
extern "C"
{
/**
* Param sentence: pointer to sentence received by NextHooker (UTF-16).
2018-07-30 14:56:45 +08:00
* You should not modify this sentence. If you want NextHooker to receive a modified sentence, copy it into your own buffer and return that.
2018-07-30 05:35:40 +08:00
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
* Return value: pointer to sentence NextHooker takes for future processing and display.
2018-07-30 14:56:45 +08:00
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
2018-07-30 05:35:40 +08:00
* 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!
*/
2018-07-31 02:29:48 +08:00
__declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
2018-07-30 05:35:40 +08:00
{
2018-07-31 02:29:48 +08:00
#if 0
2018-07-30 05:35:40 +08:00
// This example extension places sentences from the hook currently selected by the user into the clipboard
if (GetProperty("current select", miscInfo))
{
HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, (wcslen(sentence) + 1) * sizeof(wchar_t));
memcpy(GlobalLock(hMem), sentence, (wcslen(sentence) + 1) * sizeof(wchar_t));
GlobalUnlock(hMem);
OpenClipboard(0);
EmptyClipboard();
SetClipboardData(CF_UNICODETEXT, hMem);
CloseClipboard();
}
2018-07-30 14:56:45 +08:00
return sentence; // Return the original since no modifications were made.
2018-07-30 05:35:40 +08:00
#else
// This example extension adds extra newlines to all sentences
2018-07-31 02:29:48 +08:00
// Create a new buffer since the sentence needs to be modified. No need to worry about freeing this: NextHooker does it for you.
// Please allocate the buffer using malloc() and not new[] or something else: NextHooker uses free() to free it.
wchar_t* newSentence = (wchar_t*)malloc((wcslen(sentence) + 6) * sizeof(wchar_t));
2018-07-30 05:35:40 +08:00
swprintf(newSentence, wcslen(sentence) + 6, L"%s\r\n", sentence);
return newSentence;
#endif
}
}
2018-07-12 08:07:22 +08:00