Click here to Skip to main content
15,940,173 members
Home / Discussions / C#
   

C#

 
GeneralRe: Data format for non-computerist editing Pin
OriginalGriff23-Dec-20 19:44
mveOriginalGriff23-Dec-20 19:44 
GeneralRe: Data format for non-computerist editing Pin
trønderen24-Dec-20 9:44
trønderen24-Dec-20 9:44 
AnswerRe: Data format for non-computerist editing Pin
Gerry Schmitz23-Dec-20 6:46
mveGerry Schmitz23-Dec-20 6:46 
AnswerRe: Data format for non-computerist editing Pin
Mycroft Holmes23-Dec-20 11:14
professionalMycroft Holmes23-Dec-20 11:14 
AnswerRe: Data format for non-computerist editing Pin
jschell29-Dec-20 6:54
jschell29-Dec-20 6:54 
QuestionHow to address SQL CE file path? Pin
Alex Dunlop22-Dec-20 7:46
Alex Dunlop22-Dec-20 7:46 
AnswerRe: How to address SQL CE file path? Pin
OriginalGriff22-Dec-20 8:45
mveOriginalGriff22-Dec-20 8:45 
QuestionWhy does NullReferenceException throw irrelevantly? I already tried - no success. Pin
Jens Eckervogt22-Dec-20 0:18
Jens Eckervogt22-Dec-20 0:18 
Hello everyone,

I have written Wrapper with Wayland but it looks really crazy if I use DisplayGetRegistry and it throws NullReferenceException. I have tried and no success.

I have written like simple alternative to DLLImport:

C#
// Loading with current delegated method
        private enum Libraries
        {
            Client,
            Server,
            Cursor,
            Egl,
            Shm,
            V4l
        }

        private const string libdl = "libdl.so.2";
        [DllImport(libdl)]
        private extern static IntPtr dlopen(string sofile, uint soflag);
        [DllImport(libdl)]
        private extern static IntPtr dlsym(IntPtr sohandle, string functionname);
        private const uint LAZY = 0x0001;
        private static T LoadFunction<T>(string name, Libraries libraries)
        {
            IntPtr sohandle = IntPtr.Zero;
            switch (libraries)
            {
                case Libraries.Client:
                    sohandle = dlsym(dlopen("libwayland-client.so.0", LAZY), name);
                    break;

                case Libraries.Server:
                    sohandle = dlsym(dlopen("libwayland-server.so.0", LAZY), name);
                    break;

                case Libraries.Cursor:
                    sohandle = dlsym(dlopen("libwayland-cursor.so.0", LAZY), name);
                    break;

                case Libraries.Egl:
                    sohandle = dlsym(dlopen("libwayland-egl.so.1", LAZY), name);
                    break;
            }

            if (sohandle == IntPtr.Zero)
            {
                return default(T);
            }

            return (T)(object)Marshal.GetDelegateForFunctionPointer(sohandle, typeof(T));
        }


And I create for struct wl_registry *wl_display_get_registry(struct wl_display *display);

C#
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        private delegate IntPtr wl_display_get_registry(IntPtr display);
        public static Registry DisplayGetRegistry(Display display)
        {
            var emit = LoadFunction<wl_display_get_registry>("wl_display_get_registry", Libraries.Client);
            return emit(display);
        }


Both Registry and Display are classes or structure "implicit operator" with IntPtr
Example:

C#
[StructLayout(LayoutKind.Sequential)]
        public class Display
        {
            private IntPtr handle;
            internal Display(IntPtr target)
            {
                handle = target;
            }

            public static implicit operator IntPtr(Display display)
            {
                return display.handle;
            }
            public static implicit operator Display(IntPtr target)
            {
                return new Display(target);
            }
        }

        [StructLayout(LayoutKind.Sequential)]
        public class Registry
        {
            private IntPtr handle;
            internal Registry(IntPtr target)
            {
                handle = target;
            }

            public static implicit operator IntPtr(Registry registry)
            {
                return registry.handle;
            }
            public static implicit operator Registry(IntPtr target)
            {
                return new Registry(target);
            }
        }


I will explain how do I declare with struct wl_registry_listener with global and global_remove:
C#
[StructLayout(LayoutKind.Sequential)]
        public struct RegistryListener
        {
            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public unsafe delegate void AddListener(void* data, Registry registry, uint name, string registry_interface, uint version);

            [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
            public unsafe delegate void RemoveListener(void* data, Registry registry, uint name);

            /*
             * void (*global)(void *data,
             *      struct wl_registry *wl_registry,
             *      uint32_t name,
             *      const char *interface,
             *      uint32_t version)
             */
            public AddListener global;

            /*
             * void (*global_remove)(void *data,
             *      struct wl_registry *wl_registry,
             *      uint32_t name);
             */
            public RemoveListener global_remove;
        }


And I make simple Program.cs and It throws "NullReferenceException".
Simple Program.cs:

C#
using System;
using static Wayland.WLC;

namespace WaylandTest
{
    unsafe class MainClass
    {
        protected static Display display;
    //    private static Compositor compositor = null;

        private static void global_registry_handle(void* data, Registry registry, uint name, string registry_interface, uint id)
        {
            Console.WriteLine($"Get a registry event for {registry_interface} id {id}");
            if (StringCompute(registry_interface, "wl_compositor"))
            {
                //compositor = 
            }
        }

        private static void global_registry_remove(void* data, Registry registry, uint id)
        {

        }


        private static RegistryListener registry_listener = new RegistryListener
        {
            global = global_registry_handle,
            global_remove = global_registry_remove
        };

        static int Main(string[] args)
        {
            display = DisplayConnect(null);
            if (display == null)
            {
                Console.WriteLine("Can't connect to display\\n");
                Environment.Exit(1);
            }
            Console.WriteLine("connected to display\\n");

            Registry registry = DisplayGetRegistry(display);
            RegistryAddListener(registry, ref registry_listener, null);
            DisplayDispatch(display);
            DisplayRoundTrip(display);

            /*if (compositor == null)
            {
                Console.WriteLine("Can't find compositor\\n");
                Environment.Exit(1);
            }
            else
            {
                Console.WriteLine("Found compositor\n");
            }*/

            DisplayDisconnect(display);
            Console.WriteLine("disconnected from display\\n");

            Environment.Exit(0);
            return 0;
        }

    }
}


How do I fix?

And I have proted from C++ to C# this in registry.

modified 22-Dec-20 6:26am.

AnswerRe: Why does NullReferenceException throw irrelevantly? I already tried - no success. Pin
Richard MacCutchan22-Dec-20 1:06
mveRichard MacCutchan22-Dec-20 1:06 
AnswerRe: Why does NullReferenceException throw irrelevantly? I already tried - no success. Pin
OriginalGriff22-Dec-20 1:12
mveOriginalGriff22-Dec-20 1:12 
AnswerRe: Why does NullReferenceException throw irrelevantly? I already tried - no success. Pin
Gerry Schmitz22-Dec-20 3:33
mveGerry Schmitz22-Dec-20 3:33 
SuggestionSQLLight vs SQL CE Pin
Alex Dunlop20-Dec-20 8:16
Alex Dunlop20-Dec-20 8:16 
GeneralRe: SQLLight vs SQL CE Pin
Gerry Schmitz20-Dec-20 9:19
mveGerry Schmitz20-Dec-20 9:19 
GeneralRe: SQLLight vs SQL CE Pin
Mycroft Holmes20-Dec-20 11:15
professionalMycroft Holmes20-Dec-20 11:15 
QuestionHow to save panel content into PDF Pin
RedPandinus19-Dec-20 17:46
RedPandinus19-Dec-20 17:46 
AnswerRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 19:57
mveOriginalGriff19-Dec-20 19:57 
SuggestionRe: How to save panel content into PDF Pin
RedPandinus19-Dec-20 20:30
RedPandinus19-Dec-20 20:30 
GeneralRe: How to save panel content into PDF Pin
OriginalGriff19-Dec-20 22:57
mveOriginalGriff19-Dec-20 22:57 
GeneralRe: How to save panel content into PDF Pin
RedPandinus20-Dec-20 6:07
RedPandinus20-Dec-20 6:07 
GeneralAForge Motion Detection from PictureBox? Pin
Herboren19-Dec-20 17:15
Herboren19-Dec-20 17:15 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz19-Dec-20 21:51
mveGerry Schmitz19-Dec-20 21:51 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 6:09
Herboren20-Dec-20 6:09 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz20-Dec-20 9:30
mveGerry Schmitz20-Dec-20 9:30 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Herboren20-Dec-20 12:47
Herboren20-Dec-20 12:47 
GeneralRe: AForge Motion Detection from PictureBox? Pin
Gerry Schmitz21-Dec-20 6:52
mveGerry Schmitz21-Dec-20 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.