From f3225970a437746883607a7aeba1730e3909b031 Mon Sep 17 00:00:00 2001 From: manjaro-xfce Date: Sun, 22 Aug 2021 16:04:46 +0800 Subject: [PATCH] DLL Test Project Added --- findfoo/findfoo.pro | 5 +++ findfoo/findfoo/findfoo.cpp | 76 ++++++++++++++++++++++++++++++++ findfoo/findfoo/findfoo.h | 15 +++++++ findfoo/findfoo/findfoo.pro | 19 ++++++++ findfoo/findfoo/findfoo_global.h | 22 +++++++++ findfoo/test/main.cpp | 19 ++++++++ findfoo/test/test.pro | 17 +++++++ 7 files changed, 173 insertions(+) create mode 100644 findfoo/findfoo.pro create mode 100644 findfoo/findfoo/findfoo.cpp create mode 100644 findfoo/findfoo/findfoo.h create mode 100644 findfoo/findfoo/findfoo.pro create mode 100644 findfoo/findfoo/findfoo_global.h create mode 100644 findfoo/test/main.cpp create mode 100644 findfoo/test/test.pro diff --git a/findfoo/findfoo.pro b/findfoo/findfoo.pro new file mode 100644 index 0000000..e63ef51 --- /dev/null +++ b/findfoo/findfoo.pro @@ -0,0 +1,5 @@ +TEMPLATE = subdirs +SUBDIRS += \ + findfoo \ + test + diff --git a/findfoo/findfoo/findfoo.cpp b/findfoo/findfoo/findfoo.cpp new file mode 100644 index 0000000..9cae85d --- /dev/null +++ b/findfoo/findfoo/findfoo.cpp @@ -0,0 +1,76 @@ +#include "findfoo.h" +#include +#include +class Findfoo +{ +public: + Findfoo(const std::string & task = "foo"); + ~Findfoo(); +public: + void setTask(const std::string & task); + const std::string & task() const; + long long Find(const std::string & rawStr); +private: + std::string m_task = "foo"; +}; + + +Findfoo::Findfoo(const std::string & task) + :m_task(task) +{ +} +Findfoo::~Findfoo() +{ + +} + +void Findfoo::setTask(const std::string & task) +{ + m_task = task; +} +const std::string & Findfoo::task() const +{ + return m_task; +} + +long long Findfoo::Find(const std::string & rawStr) +{ + return rawStr.find(m_task); +} + +//----------- + +FINDFOO_EXPORT FFHANDLE FOOCALL ff_init_task(const char * task) +{ + Findfoo * f = new Findfoo(task); + return (FFHANDLE) f; +} + +FINDFOO_EXPORT void FOOCALL ff_reset_task(FFHANDLE h, const char * task) +{ + Findfoo * f = reinterpret_cast(h); + assert(f); + f->setTask(task); + +} + +FINDFOO_EXPORT const char * FOOCALL ff_get_task(FFHANDLE h) +{ + Findfoo * f = reinterpret_cast(h); + assert(f); + return f->task().c_str(); +} + +FINDFOO_EXPORT long long FOOCALL ff_find(FFHANDLE h, const char * rawStr) +{ + Findfoo * f = reinterpret_cast(h); + assert(f); + return f->Find(rawStr); +} + +FINDFOO_EXPORT void FOOCALL ff_fini_task(FFHANDLE h) +{ + Findfoo * f = reinterpret_cast(h); + if (f) + delete f; +} diff --git a/findfoo/findfoo/findfoo.h b/findfoo/findfoo/findfoo.h new file mode 100644 index 0000000..c88e7c7 --- /dev/null +++ b/findfoo/findfoo/findfoo.h @@ -0,0 +1,15 @@ +#ifndef FINDFOO_H +#define FINDFOO_H +#include "findfoo_global.h" +#ifdef __cplusplus +extern "C"{ +#endif +FINDFOO_EXPORT FFHANDLE FOOCALL ff_init_task (const char * task); +FINDFOO_EXPORT void FOOCALL ff_reset_task (FFHANDLE h , const char * task); +FINDFOO_EXPORT const char * FOOCALL ff_get_task (FFHANDLE h ); +FINDFOO_EXPORT long long FOOCALL ff_find (FFHANDLE h , const char * rawStr); +FINDFOO_EXPORT void FOOCALL ff_fini_task (FFHANDLE h ); +#ifdef __cplusplus +} +#endif +#endif // FINDFOO_H diff --git a/findfoo/findfoo/findfoo.pro b/findfoo/findfoo/findfoo.pro new file mode 100644 index 0000000..0393e60 --- /dev/null +++ b/findfoo/findfoo/findfoo.pro @@ -0,0 +1,19 @@ +CONFIG -= qt + +TEMPLATE = lib +DEFINES += FINDFOO_LIBRARY +DESTDIR = $$OUT_PWD/../bin +CONFIG += c++11 + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + findfoo.cpp + +HEADERS += \ + findfoo_global.h \ + findfoo.h + + diff --git a/findfoo/findfoo/findfoo_global.h b/findfoo/findfoo/findfoo_global.h new file mode 100644 index 0000000..14c8b48 --- /dev/null +++ b/findfoo/findfoo/findfoo_global.h @@ -0,0 +1,22 @@ +#ifndef FINDFOO_GLOBAL_H +#define FINDFOO_GLOBAL_H + +#if defined(_MSC_VER) || defined(WIN64) || defined(_WIN64) || defined(__WIN64__) || defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) +# define Q_DECL_EXPORT __declspec(dllexport) +# define Q_DECL_IMPORT __declspec(dllimport) +# define FOOCALL __stdcall +#else +# define Q_DECL_EXPORT __attribute__((visibility("default"))) +# define Q_DECL_IMPORT __attribute__((visibility("default"))) +# define FOOCALL +#endif + +#if defined(FINDFOO_LIBRARY) +# define FINDFOO_EXPORT Q_DECL_EXPORT +#else +# define FINDFOO_EXPORT Q_DECL_IMPORT +#endif + +#define FFHANDLE void * + +#endif // FINDFOO_GLOBAL_H diff --git a/findfoo/test/main.cpp b/findfoo/test/main.cpp new file mode 100644 index 0000000..34eb39a --- /dev/null +++ b/findfoo/test/main.cpp @@ -0,0 +1,19 @@ +#include +#include +#include "findfoo.h" +using namespace std; + +int main() +{ + FFHANDLE h = ff_init_task("foobar"); + assert(h); + cout << "Task string:" << ff_get_task(h) << endl; + cout << "Input String:"; + std::string strRaw; + cin >> strRaw; + cout << ff_find(h,strRaw.c_str()); + //Delete + ff_fini_task(h); + h = nullptr; + return 0; +} diff --git a/findfoo/test/test.pro b/findfoo/test/test.pro new file mode 100644 index 0000000..eeab070 --- /dev/null +++ b/findfoo/test/test.pro @@ -0,0 +1,17 @@ +TEMPLATE = app +CONFIG += console c++11 +CONFIG -= app_bundle +CONFIG -= qt + +SOURCES += \ + main.cpp +DESTDIR = $$OUT_PWD/../bin +INCLUDEPATH += ../findfoo + +if (*static*){ + message($$QMAKESPEC); + LIBS += -lfindfoo.dll -L$$DESTDIR +} +else{ + LIBS += -lfindfoo -L$$DESTDIR +} -- GitLab