# Writing Native Plugins

Writing Native plugins is pretty simple, but since it's C/C++ it's a bit more complicated.

There are currently no C++ bindings and no intention to write them, but the C API is still usable from C++.

          #include <gplugin.h>
          #include <gplugin-native.h>

          /* gplugin_plugin_query is called by the native loader to determine if
           * the plugin is loadable.  It must have this signature and should
           * return a valid GPluginPluginInfo instance if everything is fine.  If
           * something went wrong, error should be set to a valid GError and NULL
           * should be returned.
           */
          G_MODULE_EXPORT GPluginPluginInfo *
          gplugin_plugin_query(GError **error) {
              /* Authors is a list of authors who worked on the plugin.  Generally
               * these are in the "Name Surname <user@domain.com>" format.
               */
              const gchar * const authors[] = {
                  "Author O <author@example.com>",
                  NULL
              };

              /* gplugin_plugin_info_new only requires that the id be set, and the
               * rest are here for demonstration purposes.
               */
              return gplugin_plugin_info_new(
                  "gplugin/basic-native-plugin",
                  GPLUGIN_NATIVE_PLUGIN_ABI_VERSION,
                  "name", "name",
                  "version", "version",
                  "summary", "summary",
                  "description", "description",
                  "authors", authors,
                  "website", "website",
                  NULL);
          }

          /* gplugin_plugin_load is called by the loader when the plugin should
           * be loaded.  It must have this exact signature and return TRUE if
           * loading was successful, otherwise it should return FALSE with error
           * set to a valid GError.
           */
          G_MODULE_EXPORT gboolean
          gplugin_plugin_load(GPluginNativePlugin *plugin, GError **error) {
              return TRUE;
          }

          /* gplugin_plugin_unload is called by the loader when the plugin should
           * be unloaded.  It must have this exact signature and should return TRUE
           * if unloading was successful, otherwise it should return FALSE with
           * error set to a valid GError.
           */
          G_MODULE_EXPORT gboolean
          gplugin_plugin_unload(GPluginNativePlugin *plugin, GError **error) {
              return TRUE;
          }