Location | Tag | Media  ||  A | P

==== test.h

#if !defined(__TEST_H__)
#define __TEST_H__

#include <gtk/gtk.h>

void create_dlg ( GtkButton *button, GtkWindow *parent ) ;


#endif /* __TEST_H__ */

 

==== test.c

 

// cc -shared -Wall -g `pkg-config --cflags --libs gtk+-2.0` test.c -o libtest.so

 

#include <gtk/gtk.h>


#include "test.h"


void create_dlg (GtkButton *button, GtkWindow *parent)
{
  GtkWidget *dialog, *label, *image, *hbox;
  
  /* Create a new dialog with one OK button. */
  dialog = gtk_dialog_new_with_buttons ("Information", parent,
                                        GTK_DIALOG_MODAL,
                                        GTK_STOCK_OK, GTK_RESPONSE_OK,
                                        NULL);

  gtk_dialog_set_has_separator (GTK_DIALOG (dialog), FALSE);

  label = gtk_label_new ("The button was clicked!");
  image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, 
                                    GTK_ICON_SIZE_DIALOG);

  hbox = gtk_hbox_new (FALSE, 5);
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
  gtk_box_pack_start_defaults (GTK_BOX (hbox), image);
  gtk_box_pack_start_defaults (GTK_BOX (hbox), label);

  /* Pack the dialog content into the dialog's GtkVBox. */
  gtk_box_pack_start_defaults (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox);
  gtk_widget_show_all (dialog);

  /* Create the dialog as modal and destroy it when a button is pressed. */
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
  
}

 


 

 

 

==== dialogs.c


// # cc -Wall -g `pkg-config --cflags --libs gtk+-2.0` dialogs.c -o dialogs -ldl
//   실행전 # export LD_LIBRARY_PATH=`pwd` 
//


#include <gtk/gtk.h>

#include <dlfcn.h>

void  *FunctionLib;  /*  Handle to shared lib file */

int   (*Function)(GtkButton * , GtkWindow * );  /*  Pointer to loaded routine */

const char *dlError;  /*  Pointer to error string  */

 

static void button_clicked (GtkButton*, GtkWindow*);

int main (int argc, 
          char *argv[])
{
  GtkWidget *window, *button;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title (GTK_WINDOW (window), "Dialogs");
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  g_signal_connect (G_OBJECT (window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  button = gtk_button_new_with_mnemonic ("_Click Me");

  g_signal_connect (G_OBJECT (button), "clicked",
                    G_CALLBACK (button_clicked),
                    (gpointer) window);

  gtk_container_add (GTK_CONTAINER (window), button);
  gtk_widget_show_all (window);

  gtk_main ();
  return 0;
}

/* Create a new GtkDialog that will tell the user that the button was clicked. */
static void
button_clicked (GtkButton *button,
                GtkWindow *parent)
{
  int rc ; 
  
  FunctionLib = dlopen("libtest.so",RTLD_LAZY);

  dlError = dlerror();

  printf(" Test  3-Open Library with absolute path return-%s- \n", dlError);

  if( dlError ) exit(1);

 
  
  Function    = dlsym( FunctionLib, "create_dlg");

  dlError = dlerror();

  printf(" dlTest  8-Find symbol printLowercase return-%s- \n", dlError);

  if( dlError ) exit(1);


 

  rc = (*Function)( button , parent );

  printf(" dlTest  9-printLowercase return-%s- \n", dlError);

 
  rc = dlclose(FunctionLib);

  dlError = dlerror();

  printf(" dlTest 10-Close handle return-%s-\n",dlError);

  if( rc ) exit(1);
  
 


}


Posted by Bestend
: