Creating a mixed-mode C ++ bridge from C to C #?

I hope someone can help me with this, I am mainly a C # developer, so my C and C ++ Skills are bad. I have a native C dll, which is a wider application plugin. I cross compile this dll for windows on linux using gcc.

In my native dll, when I create a D3DSurface, I want to call a function in a C ++ mixed mode Dll and pass a pointer to the surface along with the Hwnd / handle. This C ++ mixed mode 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 to be called from a mixed mode assembly

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

Since I suck in C ++, I just want to know if anyone can give me an example of what I need to encode mixed mode dll. I would also like to not need to compile a mixed mode dll with directx headers, so is there a way I can overlay 'C' LPDIRECT3DSURFACE in a shared pointer? In C #, I use IntPtr anyway.

+3
c ++ c # interop mixed-mode
source share
3 answers

Create a managed C ++ (C ++ / CLI) DLL project that will be called from C and also be able to reference other .NET assemblies (namely, your C # thing). Then you need your whole C ++ / CLI bridge - convert data types from HWND to IntPtr, etc.

+2
source share

Have you looked at Microsoft XNA ? He allegedly ran wrappers for DirectX.

+1
source share

You can use void * in a mixed-mode DLL. There is an implicit translation from a pointer to any (including a pointer to IDirect3DSurface ) to void * . Then you can point this pointer to IntPtr .

0
source share

All Articles