Re: [OBORONA-SPAM] Re: Gtk::Module



Hello, Bob.

You wrote 3 ìàðòà 2006 ã., 20:04:00:

> Alexander Volosatov wrote:

>>>>Try this:
>>>>      
>>>>
>>
>>  
>>
>>>>Glib::Module module("libfsdyn.dll");
>>>>      
>>>>
>>  
>>  
>>
>>>>if (module)
>>>>{
>>>>   void (*function)(void);
>>>>   cout << "Module found\n";
>>>>   module.get_symbol("func1", function);
>>>>   (*function)();
>>>>}
>>>>      
>>>>
>>
>>
>>  
>>
>>>>Bob
>>>>      
>>>>
>>
>>  
>>
>>>It doesn't work.
>>>    
>>>
>>
>>Code of lib:
>>
>>#include <iostream>
>>
>>void func1()
>>{
>>     std::cout << "dll func\n";
>>}
>>
>>
>>and main program:
>>
>>#include <iostream>
>>#include <glibmm.h>
>>
>>using namespace std;
>>
>>int main (int argc, char *argv[])
>>{
>>  cout << "Hello World!" << endl;
>>  
>>        Glib::Module module("libfsdyn.dll");
>>  
>>        if (module)
>>        {
>>                cout << "Module found\n";
>>                void (*function)(void);
>>                std::string str("func1");
>>                if (module.get_symbol(str, (void *&)function))
>>                {
>>                        cout << "function loaded\n";
>>                        function();
>>                }
>>                else
>>                {
>>                        cout << "fuction not loaded\n";
>>                }
>>        }
>>  
>>  cout << "Press ENTER to continue..." << endl; 
>>  cin.get();
>>  return 0;
>>}
>>
>>
>>log:
>>Hello World!
>>Module found
>>fuction not loaded
>>Press ENTER to continue...
>>
>>WHY FUNCTION IS NOT FOUND????
>>
>>  
>>
> I do not use Glib::Module.  I do it this way:


> #include <dlfcn.h>

> // function to execute the library function designated in the XML
> // file.
> void MainMenu::on_menu_others(Glib::ustring execname)
> {
>     void (*menuitem)(void);
>     char *error;
>     char *libname =
> g_strdup_printf("/usr/flib/%s.so",execname.c_str());
   
>     Glib::ustring quit = "quit";
   
>     // if the user selected quit just leave town
>     if(quit == execname)
>     {
>         g_free(libname);
>         hide();
>         return;
>     }
  
>     if(!execname.length())
>     {
>         g_free(libname);
>         return;
>     }
   
>     void *handle = dlopen (libname, RTLD_NOW);
   
>     if(!handle)
>     {
>         error = dlerror();
>         printf("Could not open %s, error: %s\n",libname,error);
>         g_free(libname);
>         return;
>     }
   
>     g_free(libname);
   
>     menuitem = (void (*)(void))dlsym(handle, (char *)execname.c_str());
   
>     if ((error = dlerror()) != NULL)
>     {
>         printf("Error: %s\n",error);
>         return;
>     }
   
>     (*menuitem)();
   
>    dlclose(handle);
   
> }


> You'll need to use the following when you compile and link:

> `pkg-config --cflags --libs libgnome-2.0`

> Hope this helps.

> Bob

using dlfcn.h is very easy, but .... MinGW under Windows don't have it
:(

-- 
 Alexander                          mailto:rope-walker yandex ru




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]