创建一个混合模式C ++大桥从C到C#? [英] Creating a Mixed Mode C++ Bridge from C to C#?

查看:162
本文介绍了创建一个混合模式C ++大桥从C到C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望有人能帮助我,我主要是C#开发人员,所以我的
C和C ++技能是坏的。我有一个原生的C DLL这是一个
较大的应用程序的插件。我交叉编译该DLL在Linux上$ B $窗口b按GCC。

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.

在本机DLL当我创建一个D3DSurface我要调用一个函数
在混合模式C ++ DLL和传递指针沿着
与HWND /手柄表面。 。然后,该混合模式C ++应该叫我的C#
托管代码

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.

作为一个例子,在CI要做到以下几点;

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

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

在C#我想这个从混合模式组装

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
    }
}

自从我吸在C ++中,我只是想知道,如果有人可以给我什么,我需要为混合模式DLL编写一个
的例子。我也很喜欢
到不必编译与DirectX头的混合模式DLL,所以
有一个方法可以让我施展的'C'LPDIRECT3DSURFACE成一个通用的
指针?在C#中我只是使用的IntPtr反正。

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.

推荐答案

创建一个托管C ++(C ++ / CLI)DLL,这将是调用从C,也可以参考其他项目.NET程序集(即你的C#的事)。然后,所有你的C ++ / CLI桥必须做的是从HWND的转换数据类型IntPtr的,等等。

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.

这篇关于创建一个混合模式C ++大桥从C到C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆