互操作 [英] interop

查看:81
本文介绍了互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一套用C ++编写的类源,我想使用C#中的那些,可以

我只是把它们变成了一个常规DLL并导出这些和DllImport这些来自C#的
没有问题?


这很容易吗?

解决方案




您不能将DllImport用于类,只能使用普通的C风格函数。

因此,你应该实现一种Facade API作为托管代码和非托管面向对象的C ++代码之间的桥梁。


你也可以公开你的通过COM的C ++类 - 这将在一定程度上保留非托管库的

面向对象,但是

也需要更多的努力。


-

Dmitriy Lapshin [C#/ .NET MVP]

X-Unity测试工作室
http://www.x-unity.net /teststudio.aspx

将单元测试的强大功能带到VS .NET IDE


<。>在消息新闻中写道:uj ************* @tk2msftngp13.phx.gbl ...



我有一套使用C ++中的类源代码,我想使用C#中的那些,
我可以将它们变成常规DLL并导出这些和DllImport这些来自C#的没有问题吗?
这很容易吗?




我不能进行混合模式组装吗?


我的意思是我在这里有类源(它不是我的),我可以在C ++中创建一个新的.NET

程序集并使其对C#可见吗?


" Dmitriy Lapshin [C#/ .NET MVP]" < X - **** @ no-spam-please.hotpop.com>在消息新闻中写了

:uV ************** @ tk2msftngp13.phx.gbl ...


您不能将DllImport与类一起使用,只能使用普通的C风格函数。
因此,您应该实现一种Facade API作为托管代码和非托管代码之间的桥梁。面向对象的C ++
代码。
你也可以通过COM公开你的C ++类 - 这将在一定程度上保留你的非托管库的面向对象,但是会
还需要更多的努力。

- Dmitriy Lapshin [C#/ .NET MVP]
X-Unity测试工作室
http://www.x-unity.net/teststudio.aspx
带来的力量对VS .NET IDE进行单元测试

<。>在消息新闻中写道:uj ************* @tk2msftngp13.phx.gbl ...



我有一套C ++中的类源代码我希望使用C#中的那些,


可以

我只是将它们变成一个常规的DLL并导出这些和DllImport
这些来自C#没有问题?

是不是很容易?



我只需要最快在C#中访问这些课程的方式

我真的不关心图书馆的复杂性或s.hitness我必须使用
。我只有几天时间才能在C#中看到它:D



<。>在消息新闻中写道:u%**************** @ TK2MSFTNGP11.phx.gbl ...

我不能进行混合模式组装吗? />
我的意思是我在这里有类源(它不是我的)并且我可以在C ++中创建一个新的
..NET程序集并使其对C#可见吗?

Dmitriy Lapshin [C#/ .NET MVP]" < X - **** @ no-spam-please.hotpop.com>在消息新闻中写道:uV ************** @ tk2msftngp13.phx.gbl ...


你不能将DllImport用于类,只能使用纯C风格的
函数。

因此,你应该实现一种作为$的Facade API。 b $ ba托管代码和非托管面向对象C ++之间的桥梁


代码。


您还可以通过COM公开您的C ++类 - 这将保留你的非托管库的面向对象在某种程度上,但
也需要更多的努力。

-
Dmitriy Lapshin [C#/ .NET MVP ]
X-Unity测试工作室
http:// www.x-unity.net/teststudio.aspx
将单元测试的强大功能带到VS .NET IDE

<。>在消息新闻中写道:uj ************* @tk2msftngp13.phx.gbl ...



我有一套C ++中的类源代码我希望使用


C#中的那些,可以

我只是将它们变成常规DLL并导出这些和DllImport


这些来自C#没有问题?

这样容易吗?




Hi,

I have a set of classes source in C++ and I want to use those from C#, can
I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?

解决方案

Hi,

You cannot use DllImport with classes, only with plain C-style functions.
Therefore, you should probably implement a kind of facade API serving as a
bridge between the managed code and the unmanaged object-oriented C++ code.

You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

<.> wrote in message news:uj*************@tk2msftngp13.phx.gbl...

Hi,

I have a set of classes source in C++ and I want to use those from C#, can I just make these into a regular DLL and export these and DllImport these
from C# with no problems?

Is it that easy?




Cant I make a mixed mode assembly?

I mean I have the class source here (Its not mine) and can I make a new .NET
assembly in C++ and make it visible to C# that way?

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:uV**************@tk2msftngp13.phx.gbl...

Hi,

You cannot use DllImport with classes, only with plain C-style functions.
Therefore, you should probably implement a kind of facade API serving as a
bridge between the managed code and the unmanaged object-oriented C++ code.
You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would
also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

<.> wrote in message news:uj*************@tk2msftngp13.phx.gbl...

Hi,

I have a set of classes source in C++ and I want to use those from C#,


can

I just make these into a regular DLL and export these and DllImport these from C# with no problems?

Is it that easy?



I just need the fastest way to get access to these classses in C#
I really dont care for the complexity or s.hitness of the library I have to
use. I just have a few days to get it visible in C# :D


<.> wrote in message news:u%****************@TK2MSFTNGP11.phx.gbl...

Cant I make a mixed mode assembly?

I mean I have the class source here (Its not mine) and can I make a new ..NET assembly in C++ and make it visible to C# that way?

"Dmitriy Lapshin [C# / .NET MVP]" <x-****@no-spam-please.hotpop.com> wrote
in message news:uV**************@tk2msftngp13.phx.gbl...

Hi,

You cannot use DllImport with classes, only with plain C-style functions.

Therefore, you should probably implement a kind of facade API serving as a bridge between the managed code and the unmanaged object-oriented C++


code.


You can also expose your C++ classes through COM - this would retain the
object-orientness of your unmanaged library to a certain degree, but would also require more effort.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

<.> wrote in message news:uj*************@tk2msftngp13.phx.gbl...

Hi,

I have a set of classes source in C++ and I want to use those from

C#, can

I just make these into a regular DLL and export these and DllImport


these from C# with no problems?

Is it that easy?




这篇关于互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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