Local-MT-Extension/ExampleExtension/Extension.h

51 lines
3.9 KiB
C
Raw Normal View History

2018-09-02 00:41:53 +08:00
<EFBFBD><EFBFBD>#pragma once
2018-05-26 18:22:38 +08:00
2018-09-02 00:41:53 +08:00
#define WIN32_LEAN_AND_MEAN
2018-05-26 18:22:38 +08:00
#include <windows.h>
2018-09-22 02:50:15 +08:00
#include <cstdint>
2018-09-02 00:41:53 +08:00
#include <string>
struct InfoForExtension
{
2018-09-23 05:33:40 +08:00
const char* name;
int64_t value;
InfoForExtension* next;
2018-09-02 00:41:53 +08:00
};
2018-09-23 05:33:40 +08:00
struct SentenceInfo
2018-09-02 00:41:53 +08:00
{
2018-09-23 05:33:40 +08:00
const InfoForExtension* list;
// Traverse linked list to find info.
int64_t operator[](std::string propertyName)
{
for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value;
return 0;
}
};
2018-09-02 00:41:53 +08:00
2018-09-23 05:33:40 +08:00
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
2018-09-02 00:41:53 +08:00
/**
* You shouldn't mess with this or even look at it unless you're certain you know what you're doing.
2018-09-30 04:56:22 +08:00
* Param sentence: pointer to sentence received by Textractor (UTF-16).
* You should not modify this sentence. If you want Textractor to receive a modified sentence, copy it into your own buffer and return that.
* Please allocate the buffer using malloc() and not new[] or something else: Textractor uses free() to free it.
2018-09-02 00:41:53 +08:00
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
2018-09-30 04:56:22 +08:00
* Return value: pointer to sentence Textractor takes for future processing and display.
2018-09-02 00:41:53 +08:00
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
2018-09-30 04:56:22 +08:00
* Textractor will display the sentence after all extensions have had a chance to process and/or modify it.
2018-09-02 00:41:53 +08:00
* THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
*/
extern "C" __declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentenceArr, const InfoForExtension* miscInfo)
{
std::wstring sentence(sentenceArr);
2018-09-23 05:33:40 +08:00
if (ProcessSentence(sentence, SentenceInfo{ miscInfo }))
2018-09-02 00:41:53 +08:00
{
2018-09-30 04:56:22 +08:00
// No need to worry about freeing this: Textractor does it for you.
2018-09-02 00:41:53 +08:00
wchar_t* newSentence = (wchar_t*)malloc((sentence.size() + 1) * sizeof(wchar_t*));
2018-09-22 03:28:22 +08:00
wcscpy_s(newSentence, sentence.size() + 1, sentence.c_str());
2018-09-02 00:41:53 +08:00
return newSentence;
}
else return sentenceArr;
2018-09-02 01:21:35 +08:00
}