update for new abi

This commit is contained in:
Akash Mozumdar 2018-10-11 15:23:59 -04:00
parent fcdfaded52
commit 776e7c72f0
5 changed files with 40 additions and 27 deletions

View File

@ -151,6 +151,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Extension.cpp" /> <ClCompile Include="Extension.cpp" />
<ClCompile Include="ExtensionImpl.cpp" />
</ItemGroup> </ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets"> <ImportGroup Label="ExtensionTargets">

View File

@ -14,6 +14,9 @@
<ClCompile Include="Extension.cpp"> <ClCompile Include="Extension.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="ExtensionImpl.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Extension.h"> <ClInclude Include="Extension.h">

View File

@ -19,13 +19,14 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
/** /**
* Param sentence: sentence received by Textractor (UTF-16). * Param sentence: sentence received by Textractor (UTF-16).
* Param sentenceInfo: contains miscellaneous info about the sentence. See README.md * Param sentenceInfo: contains miscellaneous info about the sentence (see README).
* Return value: whether the sentence was modified. * Return value: whether the sentence was modified.
* Textractor will display the sentence after all extensions have had a chance to process and/or modify it. * Textractor 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! * THIS FUNCTION MAY BE RUN SEVERAL TIMES CONCURRENTLY: PLEASE ENSURE THAT IT IS THREAD SAFE!
*/ */
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo) bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo)
{ {
// Your code here...
#ifdef COPY_CLIPBOARD #ifdef COPY_CLIPBOARD
// This example extension automatically copies sentences from the hook currently selected by the user into the clipboard. // This example extension automatically copies sentences from the hook currently selected by the user into the clipboard.
if (sentenceInfo["current select"] == 1) if (sentenceInfo["current select"] == 1)

View File

@ -19,32 +19,9 @@ struct SentenceInfo
int64_t operator[](std::string propertyName) int64_t operator[](std::string propertyName)
{ {
for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value; for (auto i = list; i != nullptr; i = i->next) if (propertyName == i->name) return i->value;
return 0; throw;
} }
}; };
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo); struct SKIP {};
inline void Skip() { throw SKIP(); }
/**
* You shouldn't mess with this or even look at it unless you're certain you know what you're doing.
* 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.
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
* Return value: pointer to sentence Textractor takes for future processing and display.
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
* Textractor 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!
*/
extern "C" __declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentenceArr, const InfoForExtension* miscInfo)
{
std::wstring sentence(sentenceArr);
if (ProcessSentence(sentence, SentenceInfo{ miscInfo }))
{
// No need to worry about freeing this: Textractor does it for you.
wchar_t* newSentence = (wchar_t*)malloc((sentence.size() + 1) * sizeof(wchar_t*));
wcscpy_s(newSentence, sentence.size() + 1, sentence.c_str());
return newSentence;
}
else return sentenceArr;
}

View File

@ -0,0 +1,31 @@
#include "extension.h"
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
/**
* You shouldn't mess with this or even look at it unless you're certain you know what you're doing.
* 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 HeapAlloc() and not new[] or malloc() or something else: Textractor uses HeapFree() to free it.
* Param miscInfo: pointer to start of singly linked list containing misc info about the sentence.
* Return value: pointer to sentence Textractor takes for future processing and display. If nullptr, Textractor will destroy the sentence.
* Return 'sentence' unless you created a new sentence/buffer as mentioned above.
* Textractor 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!
*/
extern "C" __declspec(dllexport) const wchar_t* OnNewSentence(const wchar_t* sentence, const InfoForExtension* miscInfo)
{
try
{
std::wstring sentenceStr(sentence);
if (ProcessSentence(sentenceStr, SentenceInfo{ miscInfo }))
{
// No need to worry about freeing this: Textractor does it for you.
wchar_t* newSentence = (wchar_t*)HeapAlloc(GetProcessHeap(), 0, (sentenceStr.size() + 1) * sizeof(wchar_t));
wcscpy_s(newSentence, sentenceStr.size() + 1, sentenceStr.c_str());
return newSentence;
}
else return sentence;
}
catch (SKIP) { return nullptr; }
}