How do I know about private macros into C#?

Hello everyone,

I would like to know how do I get public methods from:

#define GTK_TYPE_WINDOW (gtk_window_get_type ())
[40](https://codebrowser.dev/gtk/gtk/gtk/gtkwindow.h.html#_M/GTK_WINDOW) #define GTK_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_WINDOW, GtkWindow))

What are names from public methods?

Because I want port to C# with modern construction without Marshal class and Assembly class because I am working on native aot of dotnet 7 or greater version.
I really know how do I get valid instance of gtype while GtkWindow marshals with GType or GObject?

But I have found Gir.Core from Github and it doesn’t work for native aot. That is why awfully. I want to understand how do I get Object from glib or gobject like g_object_new() or GTK_WINDOW()

C/C++ <-> C#
gchar* = sbyte*
gint = int
etc ...

And I already generate with ClangSharpPInvokeGenerator with Cairo to C# with void* or Cairo* See nuget!

But I have tried to port with C to C#.
example:
GTK_WINDOW() from example-0.c:

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
{
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_window_present (GTK_WINDOW (window));
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

In C# with InteropServieces without Marshal and Reflection without Assembly:

namespace Gtk4Test;

using static DeafMan1983.ConvFunctions;

using DeafMan1983.Interop.GTK4;
using static DeafMan1983.Interop.GTK4.Gtk;
using static DeafMan1983.Interop.GTK4.GObject;
using static DeafMan1983.Interop.GTK4.Gio;

unsafe class Program
{
    static void activate(GtkApplication* app, void* user_data)
    {
        GtkWidget* window = gtk_application_window_new (app);
        gtk_window_set_title (GTK_WINDOW(window), SBytePointerFromString("Window"));
        gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
        gtk_window_present (GTK_WINDOW(window));
    }

    static int Main(string[] args)
    {
        GtkApplication *app = gtk_application_new (SBytePointerFromString("org.gtk.example"), GApplicationFlags.G_APPLICATION_FLAGS_NONE);
        g_signal_connect (app, SBytePointerFromString("activate"), G_CALLBACK (&activate), null);
        int status = g_application_run (G_APPLICATION (app), args.Length, SByteDoublePointersFromStringArray(args));
        g_object_unref (app);
        return status;
    }
}

// EDIT It works fine with C#. Yay!!! I made Gtk4 into C#.
Look my picture:
image

G_CALLBACK as delegate* <void>

Example:

public static delegate* <void> G_CALLBACK(delegate* <GtkApplication*, void*, void> activate_callback)
{
    return (delegate* <void>)activate_callback;
}

for Activate of GtkApplication then It passes with G_CALLBACK :slight_smile:

Thank you for understanding and sorry my bad English!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.