Probleme mit dynmodulloader



  • Habe Modul Ladeprogramm für Linux geschrieben um Module dynamisch im c++ zu laden leider klappt dies nur mit void Funktionen aber nicht mit einer string Funktion.

    module.cpp

    /*
    Writen by Jan Koster release under lgpl
    
    */
    #include <iostream>
    #include <dlfcn.h>
    #include <string>
    #include <easyc.h>
    #include "module.h"
    
    using namespace std;
    using namespace easyc;
    
    string modul(string modulpath, string env){
    
        void* handle = dlopen(stringtochar(modulpath), RTLD_NOW);
        string     *iptr, (*fptr)(int);
    
        if (!handle) {
            cerr << "Cannot open library: " << dlerror() << '\n';
            return "Cannot open library: ";
        }
    
        typedef string (*loadmodul_t)();
    
        // reset errors
        dlerror();
        loadmodul_t loadmodul = (loadmodul_t) dlsym(handle, "loadmodul");
        const char *dlsym_error = dlerror();
        if (dlsym_error) {
            cerr << "Cannot load symbol 'loadmodul': " << dlsym_error <<
                '\n';
            dlclose(handle);
    
        }
    
        string temp = loadmodul();
        return temp;
    }
    

    module.h

    /*
    Writen by Jan Koster release under lgpl
    
    */
    
    #ifndef module_H
    #define module_H
    
    std::string modul(std::string modulpath, std::string env);
    
    #endif
    

    modul xml.h

    #ifndef XML_H_
    #define XML_H_
    
    class xml
    {
    private: 
    std::string readfile();
    std::string createfile();
    public:
    std::string createxml();
    };
    
    #endif
    

    module xml.cpp

    #include <iostream>
    #include <string>
    #include <map>
    #include "xml.h"
    #include "main.h"
    
    using namespace std; 
    
    extern "C" string loadmodul()
    {
        xml modulxml;
        return modulxml.createxml();
    }
    
    string xml::readfile()
    {
    
    }
    
    string  xml::createfile()
    {
    string filedata;
    filedata +="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <?xml-stylesheet href=\"testdata.xsl\" type=\"test/xsl\" ?>";
    filedata +="<!DOCTYPE testdata [";
    for( multimap<string,string>::iterator ii=testdata.begin(); ii!=testdata.end(); ++ii)
       {
          filedata =(*ii).first;
          filedata.insert(1,"!ELEMENT "); 
          filedata.insert(filedata.size() &-1,"(#PCDATA)");
    
       }
    filedata +="]><xml>";
    for( multimap<string,string>::iterator ii=testdata.begin(); ii!=testdata.end(); ++ii)
       {
          filedata +=(*ii).first;
          filedata += (*ii).second;
       }
    filedata +="</xml>";
    return filedata;
    }
    
    string xml::createxml()
    {
    
    }
    

    gdb output:

    
    

Log in to reply