compiling on Win32, and loading DLL OK
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 4 Feb 2016 06:44:04 +0000 (06:44 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Thu, 4 Feb 2016 06:44:04 +0000 (06:44 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2680 01035d8c-6547-0410-b346-abe4f91aad63

freedv-dev/src/afreedvplugin.c
freedv-dev/src/fdmdv2_main.cpp

index 6f7b08248e600236f802f1f0d09d6c9881eb9b5c..fbb0a379bc2fa60e9ae7fff616c3078d3c29b92f 100644 (file)
      [ ] 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 <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-/* 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++);
index ba63ce54169b675259990edea0be374b8150af74..051a67cb68d55a93d0a2c6970b6190745de15a7c 100644 (file)
@@ -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__