Compare commits

..

2 Commits

Author SHA1 Message Date
45Tatami ad5bd38f9d implement (cross-)compilation via meson 2023-05-23 00:12:18 +02:00
45Tatami 43fb4e028d compile fixes for cross-compilation 2023-05-23 00:09:40 +02:00
7 changed files with 85 additions and 14 deletions

4
.gitignore vendored
View File

@ -360,4 +360,6 @@ MigrationBackup/
.ionide/ .ionide/
# Fody - auto-generated XML schema # Fody - auto-generated XML schema
FodyWeavers.xsd FodyWeavers.xsd
*.swp

View File

@ -3,9 +3,29 @@
Useful for setups where the clipboard is not enough. Useful for setups where the clipboard is not enough.
See [here](https://github.com/45Tatami/native-inserter) for an example of the receiving server side. See [here](https://github.com/45Tatami/native-inserter) for an example of the receiving server side.
Requires Visual Studio 2019. Drop into VS, build x86 or x64 depending on which Textractor architecture you use.
Drop resulting dll into Textractor extension window.
Configuration done at runtime via interface. Configuration done at runtime via interface.
![Purrint_1707](https://user-images.githubusercontent.com/96940591/149813301-b10d229c-f093-43fa-a483-5848f71e9d2c.png) ![Purrint_1707](https://user-images.githubusercontent.com/96940591/149813301-b10d229c-f093-43fa-a483-5848f71e9d2c.png)
## Building
Requires Visual Studio 2019 or meson. Drop into VS, build x86 or x64 depending on which Textractor architecture you use.
Drop resulting dll into Textractor extension window.
### meson
```
meson setup build
ninja -Cbuild
```
Project includes example cross-compilation definition files for a mingw32 toolchain under `cross`.
```
# x86/32bit
meson setup --cross-file=cross/i686-w64-mingw32.txt build
# x86_64/64bit
meson setup --cross-file=cross/x86_64-w64-mingw32.txt build
```

View File

@ -1,4 +1,4 @@
#include "extension.h" #include "Extension.h"
bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo); bool ProcessSentence(std::wstring& sentence, SentenceInfo sentenceInfo);
@ -18,7 +18,7 @@ extern "C" __declspec(dllexport) wchar_t* OnNewSentence(wchar_t* sentence, const
try try
{ {
std::wstring sentenceCopy(sentence); std::wstring sentenceCopy(sentence);
int oldSize = sentenceCopy.size(); auto oldSize = sentenceCopy.size();
if (ProcessSentence(sentenceCopy, SentenceInfo{ sentenceInfo })) if (ProcessSentence(sentenceCopy, SentenceInfo{ sentenceInfo }))
{ {
if (sentenceCopy.size() > oldSize) sentence = (wchar_t*)HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sentence, (sentenceCopy.size() + 1) * sizeof(wchar_t)); if (sentenceCopy.size() > oldSize) sentence = (wchar_t*)HeapReAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sentence, (sentenceCopy.size() + 1) * sizeof(wchar_t));

View File

@ -1,5 +1,5 @@
#include "extension.h"
#include "resource.h" #include "resource.h"
#include "Extension.h"
#include <atomic> #include <atomic>
#include <codecvt> #include <codecvt>
@ -16,6 +16,7 @@
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <strsafe.h> #include <strsafe.h>
using std::filesystem::path;
using std::lock_guard; using std::lock_guard;
using std::mutex; using std::mutex;
using std::unique_lock; using std::unique_lock;
@ -24,9 +25,11 @@ using std::wstring;
using std::wstring_convert; using std::wstring_convert;
using std::codecvt_utf8_utf16; using std::codecvt_utf8_utf16;
#ifdef _MSC_VER
#pragma comment (lib, "Ws2_32.lib") #pragma comment (lib, "Ws2_32.lib")
#pragma comment (lib, "Mswsock.lib") #pragma comment (lib, "Mswsock.lib")
#pragma comment (lib, "AdvApi32.lib") #pragma comment (lib, "AdvApi32.lib")
#endif
#define MSG_Q_CAP 10 #define MSG_Q_CAP 10
#define CONFIG_APP_NAME L"TCPSend" #define CONFIG_APP_NAME L"TCPSend"
@ -88,7 +91,7 @@ void log(string const& msg)
// Freed on message handling // Freed on message handling
char* buf = (char *) GlobalAlloc(GPTR, msg.length() + 1); char* buf = (char *) GlobalAlloc(GPTR, msg.length() + 1);
msg.copy(buf, msg.length()); msg.copy(buf, msg.length());
PostMessage(win_hndl, WM_USR_LOG, NULL, (LPARAM) buf); PostMessage(win_hndl, WM_USR_LOG, (WPARAM) NULL, (LPARAM) buf);
} }
void log(wstring const& msg) void log(wstring const& msg)
@ -100,10 +103,10 @@ void log(wstring const& msg)
void toggle_want_connect() void toggle_want_connect()
{ {
PostMessage(win_hndl, WM_USR_TOGGLE_CONNECT, NULL, NULL); PostMessage(win_hndl, WM_USR_TOGGLE_CONNECT, (WPARAM) NULL, (LPARAM) NULL);
} }
void save_config(wstring const& filepath, wstring const& remote, bool connect) void save_config(path const& filepath, wstring const& remote, bool connect)
{ {
std::wofstream f{filepath, std::ios_base::trunc}; std::wofstream f{filepath, std::ios_base::trunc};
if (f.good()) { if (f.good()) {
@ -257,11 +260,11 @@ INT_PTR CALLBACK DialogProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPara
if (want_connect) { if (want_connect) {
SetDlgItemText(hWnd, IDC_BTN_SUBMIT, L"Disconnect"); SetDlgItemText(hWnd, IDC_BTN_SUBMIT, L"Disconnect");
SendMessage(edit, EM_SETREADONLY, TRUE, NULL); SendMessage(edit, EM_SETREADONLY, TRUE, (LPARAM) NULL);
} }
else { else {
SetDlgItemText(hWnd, IDC_BTN_SUBMIT, L"Connect"); SetDlgItemText(hWnd, IDC_BTN_SUBMIT, L"Connect");
SendMessage(edit, EM_SETREADONLY, FALSE, NULL); SendMessage(edit, EM_SETREADONLY, FALSE, (LPARAM) NULL);
} }
save_config(config_file_path, remote, want_connect); save_config(config_file_path, remote, want_connect);
@ -331,11 +334,11 @@ BOOL WINAPI DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved
GetCurrentDirectory(buf_sz, buf); GetCurrentDirectory(buf_sz, buf);
config_file_path = std::filesystem::path{wstring{buf}} / CONFIG_FILE_NAME; config_file_path = path{wstring{buf}} / CONFIG_FILE_NAME;
GlobalFree(buf); GlobalFree(buf);
PostMessage(win_hndl, WM_USR_LOAD_CONFIG, PostMessage(win_hndl, WM_USR_LOAD_CONFIG,
NULL, (LPARAM) config_file_path.c_str()); (WPARAM) NULL, (LPARAM) config_file_path.c_str());
// Start communication thread // Start communication thread
comm_thread = CreateThread(NULL, 0, comm_loop, NULL, 0, NULL); comm_thread = CreateThread(NULL, 0, comm_loop, NULL, 0, NULL);

View File

@ -0,0 +1,13 @@
[binaries]
c = 'i686-w64-mingw32-gcc'
cpp = 'i686-w64-mingw32-g++'
ar = 'i686-w64-mingw32-ar'
strip = 'i686-w64-mingw32-strip'
windres = 'i686-w64-mingw32-windres'
exe_wrapper = 'wine'
[host_machine]
system = 'windows'
cpu_family = 'x86'
cpu = 'i686'
endian = 'little'

View File

@ -0,0 +1,13 @@
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
windres = 'x86_64-w64-mingw32-windres'
exe_wrapper = 'wine64'
[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

20
meson.build Normal file
View File

@ -0,0 +1,20 @@
project('Textractor-TCPSender', 'cpp',
default_options : ['cpp_std=c++17'])
add_project_arguments('-DUNICODE', language : 'cpp')
compiler = meson.get_compiler('cpp')
src = files(
'TCPSender/TCPSender.cpp',
'TCPSender/ExtensionImpl.cpp'
)
windows = import('windows')
src += windows.compile_resources('TCPSender/resource.rc')
deps = []
deps += compiler.find_library('ws2_32')
library('tcpsender', src,
dependencies : deps)