title: C and GTK g_signal_connect Passing parameters
body: <p>Cannot get g_signal_connect to pass parameters correctly. Its probably because I do not understand the "c_handler" or "data" parameters. The code is here:</p>
  
  <pre><code>#include &lt;gtk/gtk.h&gt;
  
  // Function prototypes
  void my_file_saveas();
  
  // Function
  void my_file_saveas(GtkTextBuffer *buf)
  {
    // Get the start and end bounds of the buffer
    GtkTextIter start, end;
    gtk_text_buffer_get_bounds (buf, &amp;start, &amp;end);
  }
  
  int main(int argc, char *argv[])
  {
    GtkWidget *menubar;
    GtkWidget *fileMenu;
    GtkWidget *fileMh;
    GtkWidget *saveasMi;
  
    GtkWidget *view;
    GtkTextBuffer *buffer;
    GtkWidget *scroll_window;
    GtkWidget *vbox;
  
    GtkWidget *window;
  
    // Call this function first
    gtk_init(&amp;argc, &amp;argv);
  
    // Create widgets
    menubar = gtk_menu_bar_new();
    fileMenu = gtk_menu_new();
    fileMh = gtk_menu_item_new_with_label("File");
    saveasMi = gtk_menu_item_new_with_label("Save As");
  
    view = gtk_text_view_new();
    buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
  
    // Set out the menubar
    gtk_menu_shell_append(GTK_MENU_SHELL(fileMenu), saveasMi);
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(fileMh), fileMenu);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), fileMh);
  
    // Create a scroll window and add the view to it
    scroll_window = gtk_scrolled_window_new (NULL, NULL);
    gtk_container_add(GTK_CONTAINER(scroll_window), view);
  
    // Create a vertical box and add the menubar and scroll_window
    vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
    gtk_box_pack_start(GTK_BOX(vbox), scroll_window, TRUE, TRUE, 0);
  
    // Setup top level window
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_window_set_default_size(GTK_WINDOW(window), 640, 480);
  
    // Put the box in the top level window
    gtk_container_add(GTK_CONTAINER(window), vbox);
  
    // Events
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(G_OBJECT(saveasMi), "activate", G_CALLBACK(my_file_saveas), buffer);
  
    // Display the window
    gtk_widget_show_all(window);
  
    // Runs main
    gtk_main();
  
    return 0;
  }
  </code></pre>
  
  <p>It compiles OK. But the output when I run it is here:</p>
  
  <pre><code>graeme@graeme-HP-xw4300-Workstation ~/c/test $ ./ed10
  
  (ed10:2974): Gtk-CRITICAL **: gtk_text_buffer_get_bounds: assertion 'GTK_IS_TEXT_BUFFER (buffer)' failed
  </code></pre>