Re: [OBORONA-SPAM] Re: Gtk::Module
- From: Bob Caryl <bob fis-cal com>
- To: Alexander Volosatov <rope-walker yandex ru>
- Cc: no To-header on input <"unlisted-recipients: ; "@fis-cal.com>, gtkmm-list gnome org
- Subject: Re: [OBORONA-SPAM] Re: Gtk::Module
- Date: Fri, 03 Mar 2006 12:04:00 -0600
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
begin:vcard
fn:Robert Caryl
n:Caryl;Robert
org:Fiscal Systems, Inc.
adr:;;102 Commerce Circle;Madison;AL;35758;USA
email;internet:bob fis-cal com
title:Senior Software Design Engineer
tel;work:356-772-8920 X108
x-mozilla-html:TRUE
url:http://www.fis-cal.com
version:2.1
end:vcard
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]