From 2db3cff18fad2cd4cf4fcfdb98b876e5457c7ef3 Mon Sep 17 00:00:00 2001 From: drowe67 Date: Thu, 4 Feb 2016 06:44:04 +0000 Subject: [PATCH] compiling on Win32, and loading DLL OK git-svn-id: https://svn.code.sf.net/p/freetel/code@2680 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-dev/src/afreedvplugin.c | 34 ++++++++++++++++++++++++---------- freedv-dev/src/fdmdv2_main.cpp | 29 ++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 15 deletions(-) diff --git a/freedv-dev/src/afreedvplugin.c b/freedv-dev/src/afreedvplugin.c index 6f7b0824..fbb0a379 100644 --- a/freedv-dev/src/afreedvplugin.c +++ b/freedv-dev/src/afreedvplugin.c @@ -10,19 +10,33 @@ [ ] where do we put plugins? [ ] Windows build and test environment - $ gcc -Wall -fPIC -c afreedvplugin.c - $ gcc -shared -Wl,-soname,afreedvplugin.so -o afreedvplugin.so afreedvplugin.o + linux .so: + $ gcc -Wall -fPIC -c afreedvplugin.c + $ gcc -shared -Wl,-soname,afreedvplugin.so -o afreedvplugin.so afreedvplugin.o + win32 .dll: + $ i686-w64-mingw32-gcc -c afreedvplugin.c + $ i686-w64-mingw32-gcc -shared -o afreedvplugin.dll afreedvplugin.o -Wl,--out-implib,afreedvplugin_dll.a + */ #include #include #include -/* functions plugin can call */ +#ifdef _WIN32_ +#define DLL __declspec(dllexport) +#else +#define DLL +#endif + + +#ifdef LATER +/* functions plugin can call - not sure how to link to these */ int plugin_alert(char string[]); int plugin_get_persistant(char name[], char value[]); int plugin_set_persistant(char name[], char value[]); +#endif struct APLUGIN_STATES { int counter; @@ -30,7 +44,7 @@ struct APLUGIN_STATES { /* plugin functions called by host, we need to write these */ -void plugin_name(char name[]) { +void DLL plugin_name(char name[]) { sprintf(name, "aFreeDVplugIn"); } @@ -40,7 +54,7 @@ void plugin_name(char name[]) { storage as name/param_names[0], name/param_names[1] .... */ -void *plugin_open(char *param_names[], int *nparams) { +void DLL *plugin_open(char *param_names[], int *nparams) { struct APLUGIN_STATES *states; strcpy(param_names[0], "SymbolRate"); @@ -49,7 +63,7 @@ void *plugin_open(char *param_names[], int *nparams) { states = (struct APLUGIN_STATES *)malloc(sizeof(struct APLUGIN_STATES)); if (states == NULL) { - plugin_alert("Problem starting plugin!"); + // TODO: plugin_alert("Problem starting plugin!"); return NULL; } states->counter = 0; @@ -57,17 +71,17 @@ void *plugin_open(char *param_names[], int *nparams) { return (void*)states; } -void plugin_close(void *states) { +void DLL plugin_close(void *states) { free(states); } -void plugin_start(void *states) { +void DLL plugin_start(void *states) { } -void plugin_stop(void *states) { +void DLL plugin_stop(void *states) { } -void plugin_rx_samples(void *s, short samples[], int n) { +void DLL plugin_rx_samples(void *s, short samples[], int n) { struct APLUGIN_STATES *states = (struct APLUGIN_STATES*)s; printf("Got n=%d samples!\n", n); printf("samples[0] = %d samples[%d-1] = %d counter = %d\n", samples[0], n, samples[n-1], states->counter++); diff --git a/freedv-dev/src/fdmdv2_main.cpp b/freedv-dev/src/fdmdv2_main.cpp index ba63ce54..051a67cb 100644 --- a/freedv-dev/src/fdmdv2_main.cpp +++ b/freedv-dev/src/fdmdv2_main.cpp @@ -528,19 +528,29 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) // Look for Plug In m_plugIn = false; + #ifdef __WXMSW__ + wchar_t dll_path[] = L"/home/david/tmp/modem_api/afreedvplugin.dll"; + m_plugInHandle = LoadLibrary(dll_path); + #else m_plugInHandle = dlopen("/home/david/tmp/modem_api/afreedvplugin.so", RTLD_LAZY); + #endif if (m_plugInHandle) { - fprintf(stderr, "plugin: .so found\n"); - + printf("plugin: .so found\n"); + // lets get some information abt the plugIn void (*plugin_namefp)(char s[]); void *(*plugin_openfp)(char *param_names[], int *nparams); + #ifdef __WXMSW__ + plugin_namefp = (void (*)(char*))GetProcAddress((HMODULE)m_plugInHandle, "plugin_name"); + plugin_openfp = (void* (*)(char**,int *))GetProcAddress((HMODULE)m_plugInHandle, "plugin_open"); + #else plugin_namefp = (void (*)(char*))dlsym(m_plugInHandle, "plugin_name"); plugin_openfp = (void* (*)(char**,int *))dlsym(m_plugInHandle, "plugin_open"); - + #endif + if ((plugin_namefp != NULL) && (plugin_openfp != NULL)) { char s[256]; @@ -561,10 +571,14 @@ MainFrame::MainFrame(wxWindow *parent) : TopFrame(parent) wxGetApp().m_txtPlugInParam[i] = pConfig->Read(configStr, wxT("")); } } + else { - fprintf(stderr, "plugin: fps not found...\n"); + fprintf(stderr, "plugin: fps not found...\n"); } } + else { + fprintf(stderr, "plugin not found...\n"); + } //m_plugIn = true; //m_plugInName = "MyModem"; @@ -583,8 +597,13 @@ MainFrame::~MainFrame() int w; int h; - if (m_plugIn) + if (m_plugIn) { + #ifdef __WXMSW__ + FreeLibrary((HMODULE)m_plugInHandle); + #else dlclose(m_plugInHandle); + #endif + } //fclose(ft); #ifdef __WXMSW__ -- 2.25.1