From 7b3f248fabf33d15710075347afe931a18de2e8b Mon Sep 17 00:00:00 2001 From: Doug McLain Date: Mon, 15 Nov 2021 23:56:06 -0500 Subject: [PATCH] Add dynamic library loading support for Windows --- DroidStar.pro | 6 +++++- codec.cpp | 25 +++++++++++++++++++++++++ droidstar.cpp | 3 +-- main.cpp | 1 - 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/DroidStar.pro b/DroidStar.pro index e289105..1b22ddf 100644 --- a/DroidStar.pro +++ b/DroidStar.pro @@ -4,7 +4,11 @@ linux:QT += serialport CONFIG += c++11 LFLAGS += android:INCLUDEPATH += $$(HOME)/Android/android-build/include -LIBS += -limbe_vocoder -ldl +LIBS += -limbe_vocoder +!win32:LIBS += -ldl +win32:QT += serialport +win32:INCLUDEPATH += /mnt/data/src/mxe/usr/include +win32:LIBS += -L/mnt/data/src/mxe/usr/lib64 macx:QT += serialport macx::INCLUDEPATH += /usr/local/include macx:LIBS += -L/usr/local/lib -framework AVFoundation diff --git a/codec.cpp b/codec.cpp index 9ed73e9..cf274af 100644 --- a/codec.cpp +++ b/codec.cpp @@ -16,7 +16,11 @@ */ #include "codec.h" #include +#ifdef Q_OS_WIN +#include +#else #include +#endif #ifdef USE_FLITE extern "C" { @@ -164,6 +168,7 @@ bool Codec::load_vocoder_plugin() #else QString voc = config_path + "/vocoder_plugin." + QSysInfo::kernelType() + "." + QSysInfo::currentCpuArchitecture(); #endif +#if !defined(Q_OS_WIN) //QString voc = "/mnt/data/src/mbe_vocoder/vocoder_plugin.linux.x86_64.so"; void* a = dlopen(voc.toLocal8Bit(), RTLD_LAZY); if (!a) { @@ -183,6 +188,26 @@ bool Codec::load_vocoder_plugin() m_mbevocoder = create_a(); qDebug() << voc + " loaded"; return true; +#else + HINSTANCE hinstvoclib; + hinstvoclib = LoadLibrary(reinterpret_cast(voc.utf16())); + + if (hinstvoclib != NULL) { + create_t* create_a = (create_t*)GetProcAddress(hinstvoclib, "create"); + + if (create_a != NULL) { + m_mbevocoder = create_a(); + qDebug() << voc + " loaded"; + return true; + } + else{ + return false; + } + } + else{ + return false; + } +#endif } void Codec::deleteLater() diff --git a/droidstar.cpp b/droidstar.cpp index 1c08ff8..47efbef 100644 --- a/droidstar.cpp +++ b/droidstar.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include DroidStar::DroidStar(QObject *parent) : @@ -222,7 +221,7 @@ void DroidStar::process_connect() MicPermission::check_permission(); #endif -//#include "build.h" +#include "build.h" if( (m_callsign.size() < 4) || (m_dmrid < 250000) || diff --git a/main.cpp b/main.cpp index 871b932..2205b10 100644 --- a/main.cpp +++ b/main.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include "droidstar.h" int main(int argc, char *argv[])