<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Mixing C and C++ APIs</title> <link rel="stylesheet" type="text/css" href="style.css"> <meta name="generator" content="DocBook XSL Stylesheets V1.78.1"> <link rel="home" href="index.html" title="Programming with gtkmm 3"> <link rel="up" href="chapter-basics.html" title="Chapter 3. Basics"> <link rel="prev" href="sec-intermediate-types.html" title="Intermediate types"> <link rel="next" href="sec-helloworld.html" title="Hello World in gtkmm"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Mixing C and C++ APIs</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="sec-intermediate-types.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 3. Basics</th> <td width="20%" align="right"> <a accesskey="n" href="sec-helloworld.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-basics-gobj-and-wrap"></a>Mixing C and C++ APIs</h2></div></div></div> <p>You can use C APIs which do not yet have convenient C++ interfaces. It is generally not a problem to use C APIs from C++, and <span class="application">gtkmm</span> helps by providing access to the underlying C object, and providing an easy way to create a C++ wrapper object from a C object, provided that the C API is also based on the GObject system.</p> <p>To use a <span class="application">gtkmm</span> instance with a C function that requires a C GObject instance, use the <code class="function">gobj()</code> function to obtain a pointer to the underlying GObject instance. For instance</p> <p> </p> <pre class="programlisting"> Gtk::Button* button = new Gtk::Button("example"); gtk_button_do_something_new(button->gobj()); </pre> <p> </p> <p>To obtain a <span class="application">gtkmm</span> instance from a C GObject instance, use the Glib::wrap() function. For instance</p> <p> </p> <pre class="programlisting"> GtkButton* cbutton = get_a_button(); Gtk::Button* button = Glib::wrap(cbutton); </pre> <p> </p> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="sec-intermediate-types.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-basics.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-helloworld.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">Intermediate types </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> Hello World in <span class="application">gtkmm</span> </td> </tr> </table> </div> </body> </html>