Creating a Mixed Mode C++ Bridge from C to C#?
Asked Answered
P

3

4

I hope someone can help me with this, I'm mostly a C# developer so my C and C++ skills are bad. I have a native C dll that is a plugin of a larger application. I cross compile this dll for windows on linux using gcc.

In the native dll when I create a D3DSurface I want to call a function in a Mixed Mode C++ dll and pass in the pointer to the surface along with a Hwnd/handle. That Mixed Mode C++ should then call my C# managed code.

As an example, in C I want to do the following;

Hwnd handle;
LPDIRECT3DSURFACE d3dtarg;
SurfaceCreated(handle, d3dtarg);

In C# I want this called from the mixed mode assembly

public static class D3DInterop
{
    public static void SurfaceCreated(IntPtr handle, IntPtr surface)
    {
        //do work
    }
}

Since I suck at C++, I just want to know if someone can give me an example of what I need to code for the mixed mode dll. I'd also like to not have to compile the mixed mode dll with directx headers, so is there a way I can cast the 'C' LPDIRECT3DSURFACE into a generic pointer? In C# I just use the IntPtr anyway.

Privet answered 5/11, 2008 at 22:58 Comment(0)
R
3

Create a managed C++ (C++/CLI) DLL project which will be callable from C and will also be able to reference other .Net assemblies (namely your C# thing). Then all your C++/CLI bridge would have to do is translate the data types from HWND to IntPtr, etc.

Remember answered 5/11, 2008 at 22:58 Comment(0)
L
2

Have you looked into Microsoft XNA? It supposedly has managed wrappers for DirectX.

Liatris answered 6/11, 2008 at 1:1 Comment(0)
W
0

You can use void * in the mixed-mode DLL. There is an implicit cast from a pointer to anything (including a pointer to IDirect3DSurface) to void *. You can then cast that pointer to IntPtr.

Woofer answered 6/11, 2008 at 14:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.