Trying to convert C ++ to C # using interop

I have a program that calls EGL in C ++. I want to make the same call in C #, but in C # there is no equivalent concept.

I get denied read / write access when the execution context enters the EGL C ++ code.

This is the code in a C ++ program that I am trying to convert to C #:

PropertySet^ surfaceCreationProperties = ref new PropertySet();
surfaceCreationProperties->Insert(ref new String(EGLNativeWindowTypeProperty), somethingOtherThanAWindow);

mEglSurface = eglCreateWindowSurface(mEglDisplay, config, reinterpret_cast<IInspectable*>(surfaceCreationProperties), surfaceAttributes));

I have a C # class that converts C # EGL calls to C ++ calls. I believe that C ++ is unmanageable, although I do not know how to tell you for sure.

The C # class is as follows:

public static IntPtr CreateWindowSurface(IntPtr dpy, IntPtr config, IntPtr win, int[] attrib_list)
{
    IntPtr retValue;

    unsafe {
        fixed (int* p_attrib_list = attrib_list)
        {
            retValue = Delegates.peglCreateWindowSurface(dpy, config, win, p_attrib_list);
        }
    }
    return (retValue);
}

Moreover, this code can be seen here: https://github.com/luca-piccioni/OpenGL.Net/blob/master/OpenGL.Net/Egl.VERSION_1_0.cs#L751

, IntPtr win - , PropertySet. , System.Windows.Forms.Control, ++ EGL, , , PropertySet.

++:

EGLSurface EGLAPIENTRY CreateWindowSurface(EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint *attrib_list)

: https://github.com/Microsoft/angle/blob/ms-holographic-experimental/src/libGLESv2/entry_points_egl.cpp#L241

, ++ EGLNativeWindowType. , - , .

EGLNativeWindowType :

typedef HWND EGLNativeWindowType;

, . , PropertySet .

, # EGL. PropertySet , , reinterpret_cast .

- ?

0
2

, System.Windows.Forms.Control...

. , , , SO. Winforms, , .

OpenGL , api - , void*, . , , . , , . , Microsoft OpenGL , DirectX.

, , . IUnknown, QueryInterface() , . , , , IInspectable - , IUnknown, , WinRT. IInspectable *, ANGLE.

, ICoreWindow , WinRT . , ICoreWindow. , , , - WinRT. .

, OpenGL . Microsoft , , / IInspectable *, IMap<String^, IInspectable*>. , CoreWindowNativeWindow.cpp ANGLE CoreWindowNativeWindow:: initialize().

PropertySet - ++, IMap<K, V>. , ++, # Dictionary<string, IntPtr>. , CLR, IMap.

, , IntPtrs. IInpectable * , #, . , 98% Marshal.GetIUnknownForObject() , , . ++ QueryInterface:), Marshal.Release() , , .

, , . , , Microsoft ANGLE . iOS WinRT/UWP. , , . ANGLE - , ObjectiveC ++, , .

, Javascript #, , . ++, OpenGL #, , , , DirectX . HoloLens.

+3

Source: https://habr.com/ru/post/1657215/


All Articles